Running VBScript on remote computer....aaarrrrggghhh RRS feed

  • Question

  • Hello all,

    I have a vbscript that I cannot run on a remote computer, it uses psexec to run and if I run the line from a local CMD prompt it works,

    psexec.exe \\computername cscript.exe c:\wuafix\wuafix.vbs

    If I try and run it from a script as per below, it doesn't run, what am I doing wrong??the strComputer is using a input box to parse the correct computer name OK as the previous parts of the script work...all I see when I run the whole script is what looks like the psexec screen for a fraction of a second... and then the script exits

    'set command line executable to run a silent install remotely
    strInstaller1 = "cscript.exe c:\wuafix\wuafix.vbs"
    'strInstaller2 = "c:\wuafix\wuafix.vbs"
    strExec = "c:\pstools\PsExec.exe " 
    objshell.Run strExec & " \\" & strComputer & strInstaller1

    the whole script Is below which I have modified, I have only been using VB for a week so not really sure what to look for and also I know it could be tidied up, but for now I would like to get the PSEXEC line working, or is there another way to get the vbscript running on a remote machine, the file itself is copied over earlier in the script. I appreciate anyone's help on this

    'setting objects
    Dim net, objFSO, shell
    Dim objFile, strLine, intResult
    Set objnet = CreateObject("")
    Set objFSO = CreateObject("scripting.filesystemobject")
    Set objshell = CreateObject("")
    strfile = "c:\wuafix\wuafix.vbs"
    strUser = "domain\user"
    strPassword = "password"
    'getting server name or IP address
    strComputer=InputBox("Enter the IP or computer name of the remote machine on which to repair the WUA agent:", "Starting WUA Fix")
    'check to see if the server can be reached
    Dim strPingResults
    Set pingExec = objshell.Exec("ping -n 3 -w 2000 " & strComputer) 'send 3 echo requests, waiting 2secs each
    strPingResults = LCase(pingExec.StdOut.ReadAll)
    If Not InStr(strPingResults, "reply from")>0 Then
      WScript.Echo strComputer & " did not respond to ping."
    End If
    'Check if source file exists
    If Not objFSO.FileExists(strFile) Then
       WScript.Echo "The source file does not exist"
    End If
    MsgBox "The WUA Fix  is in process.  Please wait.", 64, "Script Message"
    'mapping drive to remote machine
    If objFSO.DriveExists("Z:") Then
    objnet.RemoveNetworkDrive "Z:","True","True"
    End If
    objnet.MapNetworkDrive "Z:", "\\" & strComputer & "\c$", True
    'creating folder for install exe on remote machine
    If (objFSO.FolderExists("Z:\wuafix\") = False) Then
       objFSO.CreateFolder "Z:\wuafix"
    End If
    'copying vbs to remote machine
    objFSO.CopyFile strFile, "Z:\wuafix\wuafix.vbs"
    'set command line executable to run a silent install remotely
    strInstaller1 = "cscript.exe c:\wuafix\wuafix.vbs"
    'strInstaller2 = "c:\wuafix\wuafix.vbs"
    strExec = "c:\pstools\PsExec.exe " 
    objshell.Run strExec & " \\" & strComputer & strInstaller1
    Sub Pause()
        WScript.Echo ("Press Enter to continue")
        z = WScript.StdIn.ReadLine()
    End Sub
    'checking if log file is present and parse through the log for Successful message
    'strLogFile = "z:\Program Files\APPQcime\CimExtensions\APPQcime_CIM_Extensions_InstallLog.log"
    'CONST ForReading = 1 
    'If objFSO.FileExists(strLogFile) Then
    '   Set objFile = objFSO.OpenTextFile(strLogFile, ForReading)
    '   strLine = objFile.Readline
    '   Do Until objFile.AtEndofStream 
    '    strLine = objFile.ReadLine
    '    intResult = InStr(strLine, "Installation: Successful")
    '    If intResult <>0 Then
    '   		WScript.Echo("CIM Extension Agent was installed for " & strComputer & " on " & Time & " " & Date)
    '    End If
    '   Loop  
    ' Else
    '   WScript.echo "Unable to install the agent. Please try again"
    ' End If
    'removing mapped drives
    'objnet.RemoveNetworkDrive "Z:"

    many thanks

    Friday, June 20, 2014 10:29 AM


  • Start by adding the missing space.

    On Error Resume Next
    result = objshell.Run(strExec & " \\" & strComputer & " " & strInstaller1)
    If Err Then MsgBox Err.Number
    MsgBox result

    Catch the error to see what is failing.


    • Marked as answer by MisterD101 Friday, June 20, 2014 11:32 AM
    Friday, June 20, 2014 11:02 AM