Avatar of sep2674
sep2674
 asked on

Message to remote client based on ip address through VBS script

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,
Scripting LanguagesProgrammingNetwork Management

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
RobSampson

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

sep2674

ASKER
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
ASKER CERTIFIED SOLUTION
RobSampson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sep2674

ASKER
Thank you Rob, it went fine.

Cheers :-)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
RobSampson

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.