[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1094
  • Last Modified:

Running VBScript Remotely

Can someone tell me what can be wrong with this little vbscript. I've attached teh error message. Or maybe suggest a different way to run a VBScript remotely. I can ping the IP Address successfully.

strComputer = "10.24.???.???"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
Error = objWMIService.Create("c:\scripts\z.vbs", null, null, intProcessID)
If Error = 0 Then
    Wscript.Echo "z.vbs was started with a process ID of " & intProcessID
Else
    Wscript.Echo "z.vbs could not be started due to error " & Error
End If



error.bmp
0
Bianchi928
Asked:
Bianchi928
  • 8
  • 5
  • 3
  • +1
1 Solution
 
IceCodeCommented:
Unfortunately ping does not equal access to the WMI namespace.  Are you on the same network as the machine you want to run this against?
0
 
Bianchi928Author Commented:
No we aren't on the same network, but i have admin rights to all networks
0
 
TheGorbyCommented:
I think this means you can't do what you need to:

"For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely."

http://msdn.microsoft.com/en-us/library/aa389388(v=vs.85).aspx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Bianchi928Author Commented:
Any suggestion of different methods that can be used to achieve this task ?
0
 
IceCodeCommented:
0
 
Bianchi928Author Commented:
I've tried using psexec and I still have a problem.

eg

psexec \\mycomputer c:\scripts\z.vbs

Error is : PsExec could not start c:\scripts\z.vbs on myipaddress
The system cannot file the file specified

Very strange because the file is there

Cheers


0
 
RobSampsonCommented:
Hi,

Is C:\Scripts\z.vbs on the remote machine, or on your machine?

If it's on the remote machine, it should work, but it's probably easier to put the script on a file share, and use the following:

psexec -accepteula -u domain\admin -p password \\REMOTEPC wscript.exe \\server\share\z.vbs

Regards,

Rob.
0
 
IceCodeCommented:
Are you just trying to run z.vbs on the remote machine but using another script to start it?
0
 
Bianchi928Author Commented:
Hi Rob

You got me on the right track as usual...The following code is working fine and I've included you example in there. How can I modify it to write to log of the ones that failed ?

Thanks
Cheers


set objFSO = CreateObject("Scripting.FileSystemObject")
set objShell = CreateObject("Wscript.Shell")
set objFile = objFSO.OpenTextFile("C:\documents and settings\cis0794\desktop\inputlist5.txt")

Do while not objFile.AtEndOfStream
      currentpc = objFile.Readline
      objShell.Run "d:\psexec \\" & currentpc & " -i -d -u retail\username -p password wscript.exe \\" & currentpc & "\c$\scripts\z.vbs"
Loop
0
 
RobSampsonCommented:
Hi, try this.  We can catch the return value from PSExec and report on that.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objFile = objFSO.OpenTextFile("C:\documents and settings\cis0794\desktop\inputlist5.txt")
Set objLog = objFSO.CreateTextFile("C:\Documents and settings\cis794\desktop\runscriptlog.txt")
Do while not objFile.AtEndOfStream
	currentpc = objFile.Readline
	If Ping(currentpc) = True Then
		intReturn = objShell.Run("d:\psexec \\" & currentpc & " -i -d -u retail\username -p password wscript.exe \\" & currentpc & "\c$\scripts\z.vbs", 0, True)
		If intReturn = 0 Then
			objLog.WriteLine "Script started successfully on " & currentpc
		Else
			objLog.WriteLine "Script start failed on " & currentpc & " with return code " & intReturn
		End If
	Else
		objLog.WriteLine currentpc & " is offline"
	End If
Loop
objLog.Close
objFile.Close

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

0
 
Bianchi928Author Commented:
I fixed a few little mistakes (strcomputer with currentpc). I ran it and it's hung


Any idea ?
Cheers

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objFile = objFSO.OpenTextFile("C:\documents and settings\cis0794\desktop\inputlist5.txt")
Set objLog = objFSO.CreateTextFile("C:\Documents and settings\cis0794\desktop\runscriptlog.txt")
Do while not objFile.AtEndOfStream
      currentpc = objFile.Readline
      If Ping(currentpc) = True Then
            intReturn = objShell.Run("d:\psexec \\" & currentpc & " -i -d -u retail\cis0794 -p cis0794 wscript.exe \\" & currentpc & "\c$\scripts\z.vbs", 0, True)
            If intReturn = 0 Then
                  objLog.WriteLine "Script started successfully on " & currentpc
            Else
                  objLog.WriteLine "Script start failed on " & currentpc & " with return code " & intReturn
            End If
      Else
            objLog.WriteLine currentpc & " is offline"
      End If
Loop
objLog.Close
objFile.Close

Function Ping(currentpc)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & currentpc, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
0
 
RobSampsonCommented:
Try this.  Try putting the script on a network share instead of directly on the remote PC.

Regards,

Rob.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objFile = objFSO.OpenTextFile("C:\documents and settings\cis0794\desktop\inputlist5.txt")
Set objLog = objFSO.CreateTextFile("C:\Documents and settings\cis794\desktop\runscriptlog.txt")
strScriptPath = "\\server\share\scripts\z.vbs"
Do while not objFile.AtEndOfStream
	currentpc = objFile.Readline
	If Ping(currentpc) = True Then
		intReturn = objShell.Run("d:\psexec -i -u retail\username -p password \\" & currentpc & " wscript.exe " & strScriptPath, 0, True)
		If intReturn = 0 Then
			objLog.WriteLine "Script started successfully on " & currentpc
		Else
			objLog.WriteLine "Script start failed on " & currentpc & " with return code " & intReturn
		End If
	Else
		objLog.WriteLine currentpc & " is offline"
	End If
Loop
objLog.Close
objFile.Close

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

0
 
Bianchi928Author Commented:

intReturn = objShell.Run("d:\psexec \\" & currentpc & " -i -d -u retail\cis0794 -p cis0794 wscript.exe b]\\" & currentpc & "\c$\scripts\z.vbs", 0, True)

strScriptPath = "\\server\share\scripts\z.vbs"

Isn't that the same as

\\" & currentpc & "\c$\scripts\z.vbs"  in the top line
0
 
RobSampsonCommented:
Not really.

If you tell a computer to run \\<remotepc>\c$\scripts\z.vbs then C:\Scripts\z.vbs must exist *on that remote machine*.  Whereas, if you tell a computer to run \\fileserver\share\scripts\z.vbs then all computers can have access to the same script at that share.

Rob.
0
 
Bianchi928Author Commented:
It looks that it's hung on the Ping. When I run this little program, I get a "0" and "Ok". But, if i modify your script to reflect that , it hangs.

Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolcode = objShell.Run("Ping u101c8 " , 0, True)
        wscript.echo boolcode
        If boolCode = 0 Then
                wscript.echo "Ok"
            Ping = True
      Else
                wscript.echo "Failed"
            Ping = False
      End If
0
 
RobSampsonCommented:
That's very strange. I've never had that problem....maybe it's the PSExec that's actually hanging....

Change these lines:

 
If Ping(currentpc) = True Then
		intReturn = objShell.Run("d:\psexec -i -u retail\username -p password \\" & currentpc & " wscript.exe " & strScriptPath, 0, True)
		If intReturn = 0 Then

Open in new window


to this:

 
If Ping(currentpc) = True Then
		strCommand = "d:\psexec -accepteula -i -u retail\username -p password \\" & currentpc & " wscript.exe " & strScriptPath
		InputBox "About to run:", "Command", strCommand
		intReturn = objShell.Run(strCommand, 0, True)
		If intReturn = 0 Then

Open in new window


and then you'll get an InputBox from which you can copy and paste the PSExec command to test it at a DOS prompt.

Also, make sure you're using the latest version of PSExec.exe.  I use 1.96 or 1.98 most often.

Regards,

Rob.
0
 
Bianchi928Author Commented:
That's working now. Thanks a lot..Cheers. I have a little problem with another script which I will post in 2 secs.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now