Solved

Run VBScript Remotely

Posted on 2010-09-16
8
1,589 Views
Last Modified: 2012-08-13
I have a vbscript that I run on my computer. This script checks to see if another script resides on a server. If not it will copy the script to the server at C:\. Once the script is there it should initiate the script to run on the remote server. I do have admin rights on my computer and the server. I have verified that the script works while logged onto the server and ran locally. I am using windows XP and the servers are 2003 and 2008.

Everytime I run it I get the attached error message.

Error: Catastrophic failure
Code: 8000FFFF
Source: (null)

Has anyone been able to run a script on a remote computer?

Thanks,
Function RunRemoteScript(strVBScript, strComputer)
  Set objWshController = CreateObject("WshController")
  'Wscript.ConnectObject objWshController,"WshController_"
  strRunScript = "\\" & strComputer & "\C$\ApplyUpdates2.vbs"
  Set objRemoteScript = objWshController.CreateScript(strRunScript, strComputer)
  objRemoteScript.Execute
  While objRemoteScript.Status <> 2
   WScript.Sleep 100
  WEnd
End Function

Open in new window

error.JPG
0
Comment
Question by:MountyTech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 3

Assisted Solution

by:Zach2001
Zach2001 earned 25 total points
ID: 33696826
I have ran scripts on remote machines, using PS tools:

http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 33697408
Hi, another method (that I've admittedly never had success with), is to use the Create method of the Win32_Process class.

Note that to run VBScripts, you might need to include wscript.exe in the command, so I have included a commented out line that has that.  Try both.

Regards,

Rob.
Sub RunRemoteScript(strVBScript, strComputer)
	On Error Resume Next
	Set objProcess = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
	intResult = objProcess.Create (strVBScript, Null, Null, lngProcessID)
	'intResult = objProcess.Create ("wscript.exe " & strVBScript, Null, Null, lngProcessID)
	If Err.Number <> 0 Then
		WScript.Echo "Error 0x" & Hex(Err.Number) & ": " & Err.Description
		Err.Clear
	Else
		WScript.Echo "Process created with ID of " & lngProcessID
	End If
	On Error GoTo 0
End Sub

Open in new window

0
 

Author Comment

by:MountyTech
ID: 33700514
Zach,
I was trying to stay away from pstools. I am going to run the script against a list servers. Pstools will popup a cmd screen for each one. The servers are listed in a text file.

Rob,
I tried your suggestions with no success as well.



0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 3

Expert Comment

by:Zach2001
ID: 33700553
it's a bit dirty, but why not try the AT command ?
0
 
LVL 2

Expert Comment

by:Procastin8or
ID: 33701938
Found this here:  http://motevich.blogspot.com/2007/11/execute-program-on-remote-computer.html
After being modified to fit it should work.
strComputer = "."
strCommand = "notepad.exe"

Const INTERVAL = "n"
Const MINUTES = 1

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objScheduledJob = objWMIService.Get("Win32_ScheduledJob")
Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")

objSWbemDateTime.SetVarDate(DateAdd(INTERVAL, MINUTES, Now()))
errReturn = objScheduledJob.Create(strCommand, objSWbemDateTime.Value, False, 0, 0, True, intJobID)

If errReturn = 0 Then
Wscript.Echo "notepad.exe was started with a process ID: " & intJobID
Else
Wscript.Echo "notepad.exe could not be started due to error: " & errReturn
End If

Open in new window

0
 

Author Comment

by:MountyTech
ID: 33704464
Procastin8or,
I tried the code you listed. It works great on my 2008 boxes. On the 2003 boxes I get permission errors. This is due to that the scheduled script is writing to a log on a remote share. Since the job is scheduled it must not maintain my credentials.
0
 

Author Comment

by:MountyTech
ID: 33704473
Sorry, I left out that the remote share is accessed through a unc path.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 100 total points
ID: 33706239
You can use PSExec without showing the command prompt for each server, if you process each server individually in the script (by looping through a text file of server names).  Try the code below if you're interested.

Set your username to run the program with, and it will prompt you for your password.

Regards,

Rob.
strComputers = "\\server\share\computers.txt"
strVBScript = "\\server\share\scriptname.vbs"
strPSExec = "\\server\shares\psexec.exe"
strUsername = "domain\username"
strPassword = InputBox("Enter the password for " & strUsername & ":")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objShell = CreateObject("WScript.Shell")
Set objComputers = objFSO.OpenTextFile(strComputers, intForReading, False)
While Not objComputers.AtEndOfStream
	strServer = objComputers.ReadLine
	If Ping(strServer) = True Then
		strCommand = "cmd /c " & objFSO.GetFile(strPSExec).ShortPath & " -accepteula -e -u " & strUsername & " -p " & strPassword & " \\" & strServer & " wscript.exe " & objFSO.GetFile(strVBScript).ShortPath
		intReturn = objShell.Run(strCommand, 0, True)
		If intReturn = 0 Then
			WScript.Echo "Script ran on " & strServer
		Else
			WScript.Echo "Script did not run on " & strServer
		End If
	Else
		WScript.Echo strServer & " is offline."
	End If
Wend
objComputers.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

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question