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
Avatar of RobSampson
RobSampson
Flag of Australia image

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

Avatar of sep2674
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
Avatar of RobSampson
RobSampson
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sep2674
sep2674

ASKER

Thank you Rob, it went fine.

Cheers :-)
Avatar of RobSampson
RobSampson
Flag of Australia image

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.
Programming
Programming

Programming includes both the specifics of the language you’re using, like Visual Basic, .NET, Java and others, but also the best practices in user experience and interfaces and the management of projects, version control and development. Other programming topics are related to web and cloud development and system and hardware programming.

55K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo