Message to remote client based on ip address through VBS script

sep2674
sep2674 used Ask the Experts™
on
Hi everyone,
I am a complete novice in VBS and Powershell scripts and I'd like to get some help or advice on a specific situation.
I was assigned to write a VBS script that is supposed to send a pop up with buttons on remote machines based on their IP address not their network paths. Basically, as soon as the recipient receives that message when he or she clicks on "Yes" some kind of an acknowledgement pop up should be sent to the sender advising that alert has been taken into account.

Please the below code that I've started.

"Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("Merci d'intervenir en urgence au centre d'Arts Plastiques Verdun!", 0+64, "Alerte Verdun", 4 + 48)

Select Case BtnCode
case 6 WScript.Echo "Votre confirmation est envoyée au site", "Alerte Verdun"
case 7 WScript.Echo "Merci de prendre en compte cette alerte!", "Alerte Verdun"
case -1 WScript.Echo "No Response?"

End Select
"

Thank you very much for your help.

Regards,
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, grab a copy of PSExec, specify the path to it in this script, and give this a try.

Regards,

Rob.

strPSExec = "\\server\share\psexec.exe"
strComputer = InputBox("Enter remote IP:", "Remote IP")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPSExec = objFSO.GetFile(strPSExec).ShortPath
Set objShell = CreateObject("WScript.Shell")
If Ping(strComputer) = True Then
	If objFSO.FolderExists("\\" & strComputer & "\C$") = True Then
		strScriptFile = "\\" & strComputer & "\C$\Message.vbs"
		On Error Resume Next
		Set objScript = objFSO.CreateTextFile(strScriptFile, True)
		If Err.Number = 0 Then
			On Error GoTo 0
			objScript.WriteLine "Dim WshShell, BtnCode"
			objScript.WriteLine "Set WshShell = CreateObject(""WScript.Shell"")"
			objScript.WriteLine "BtnCode = WshShell.Popup(""Merci d'intervenir en urgence au centre d'Arts Plastiques Verdun!"", 0+64, ""Alerte Verdun"", 4 + 48)"
			objScript.WriteLine "WScript.Quit(BtnCode)"
			objScript.Close
			
			strCommand = strPSExec & " -accepteula -i \\" & strComputer & " wscript.exe " & Replace(Replace(strScriptFile, "$", ":"), "\\" & strComputer & "\", "")
			intExitCode = objShell.Run(strCommand, 1, True)
			objFSO.DeleteFile strScriptFile, True
			Select Case intExitCode
				Case 6 WScript.Echo "Votre confirmation est envoyée au site", "Alerte Verdun"
				Case 7 WScript.Echo "Merci de prendre en compte cette alerte!", "Alerte Verdun"
				Case -1 WScript.Echo "No Response?"
			End Select
		Else
			WScript.Echo "Unable to create " & strScriptFile & vbCrLf & "Error " & Err.Number & ": " & Err.Description
			Err.Clear
			On Error GoTo 0
		End If
	Else
		WScript.Echo "Unable to find C$ share on " & strComputer
	End If
Else
	WScript.Echo "Unable to ping " & strComputer
End If

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

Author

Commented:
Hello Rob,
Thank you very much for that piece of code, I really appreciate it.
However, could you tell which variables I need to replace in order to make it work in my case (ie, IP address, execution paths and so on).

Sorry to bother you.

Regards,
Jimmy
Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi, the only one you really need to change is this:
strPSExec = "\\server\share\psexec.exe"

so that you point the script to the path where you have PSExec.

The script will prompt you to enter an IP address.

If you want the remote script that is automatically created to be stored somewhere other than C:\Message.vbs on the remote machine, then change this:
            strScriptFile = "\\" & strComputer & "\C$\Message.vbs"

but that's temporary anyway, and is immediately deleted after the script executes.

Regards,

Rob.

Author

Commented:
Thank you Rob, it went fine.

Cheers :-)
Most Valuable Expert 2012
Top Expert 2014

Commented:
OK sure.  May I ask whether there was anything more I could have done, since you gave a "B" grade?  Generally the Experts here feel that if their solution worked as expected, then it should be given an "A" grade.  Please keep that in mind when grading future questions.

Rob.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial