Gavriel Feria
Gavriel Feria

Reputation: 419

Show a message box on another computer in vbscript?

How do I show a message box on a running computer in your network in vbscript? I've searched everywhere and I'm not getting any answer.

Upvotes: 2

Views: 8917

Answers (2)

Panayot Karabakalov
Panayot Karabakalov

Reputation: 3179

Maybe this is a bit advanced question for VBScript, but as the WSH allow remote scripting, it's possible task for WSHController. Of course it require proper configuration and this article show some of the steps to setup this object, Microsoft's Windows Script 5.6 documentation offer more details.

There's some limitations that not allow UI interaction (like MsgBox, InputBox, etc) in remote scripts, but this can be cheated by creating another script with FileSystemObject.

You'll need 2 scripts, one that you run from your controller machine (I'll name it RemoteScript.vbs) and second that you'll copy to the target machine (Messenger.wsf). I'll post a whole code in one block here, but you'll need to copy each part in separate file.

REM ----------- RemoteScript.vbs code start here -------------

Const WshFinished = 2

Dim Controller, RemoteScript, RemoteServer
RemoteServer = "\\server_name"

Set Controller = WScript.CreateObject("WSHController")
Set RemoteScript = Controller.CreateScript("Messenger.wsf", RemoteServer)

WScript.ConnectObject RemoteScript, "WSH_"
RemoteScript.Execute

Do While RemoteScript.Status <> WshFinished 
    WScript.Sleep 200
Loop

WScript.DisconnectObject RemoteScript

Sub WSH_Error
    With RemoteScript.Error
        WScript.Echo "Error " & _
        CStr(Hex(.Number)) & " - Line: " & .Line & _
        ", Char: " & .Character & vbCrLf & _
        "Description: " & .Description
    End With
    WScript.Quit -1
End Sub

Function WSH_End()
    MsgBox "wshRemote End Event fired"
End Function

Function WSH_Start()
    MsgBox "wshRemote Start Event fired"
End Function

REM ----------- RemoteScript.vbs code end here ---------------

REM ----------- Messenger.wsf code start here ----------------

<package>
  <job>
    <script language="VBScript">
      tmpFile = "c:\_tmp711a.vbs"
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set fout = fso.CreateTextFile(tmpFile, true)
      fout.WriteLine "MsgBox ""Remote Hello"", 0, ""Example"" "
      fout.Close
      WScript.Sleep 100
      Set shell = CreateObject("WScript.Shell")
      shell.Run "wscript " & tmpFile, 1, True
      If fso.FileExists(tmpFile) Then fso.DeleteFile(tmpFile)
    </script>
  </job>
</package>

REM ----------- Messenger.wsf code end here ----------------

Upvotes: 2

Helen
Helen

Reputation: 97962

You can make use of the following Windows commands:

  • net send (not supported on Windows Vista and above; requires the Messenger service to be running)
  • msg (for Terminal Server users only)

You can execute these commands from VBScript using WshShell.Run, for example:

CreateObject("WScript.Shell").Run("net send computername Hello, world!")

Upvotes: 0

Related Questions