Link to home
Start Free TrialLog in
Avatar of Ray Drummond
Ray DrummondFlag for United States of America

asked on

Passing switches to executables thru VB Script

I'm really new to VB Script and am trying to figure out how to pass a switch to an executable thru VB Script.  What I'm doing is connection to a target machine, going to a specific directory, copying a group of files to the directory and then trying to execute a program using PSExec.  The whole process works, but the program requires a password.  There is a switch that I can pass with the password to do it, but I can't figure out the correct syntax in VB Script to do it.  The command line would look like....

c:\%systemroot%\propatches\agtinstallerx.exe /PW password

Here is the code....

For Each sLine In aComp
      'WScript.Echo sLine
      If FileSystem.FolderExists ("\\" & sLine & "\c$\winnt") Then
            sDest = "\\" & sLine & "\c$\winnt\ProPatches\"
            sRexe = """C:\winnt\ProPatches\AgtInstallerX.exe /PW password"""
      Else
            sDest = "\\" & sLine & "\c$\windows\ProPatches\"
            sRexe = """C:\windows\ProPatches\AgtInstallerX.exe /PW password!"""
      End If

Would greatly appreciate the help.
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi,

It doesn't look like you're using PSExec with the code you posted, so I'll add that for you:

Set FileSystem = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")

' Specify your path to the PSExec executable
' so you can get the short path to it
strPSExecPath = "C:\Tools\PSExec.exe"
strPSExecPath = FileSystem.GetFile(strPSExecPath).ShortPath

For Each sLine In aComp
      'WScript.Echo sLine
      If FileSystem.FolderExists ("\\" & sLine & "\c$\winnt") Then
            sDest = "\\" & sLine & "\c$\winnt\ProPatches\"
            sRexe = """C:\winnt\ProPatches\AgtInstallerX.exe"" /PW password"
      Else
            sDest = "\\" & sLine & "\c$\windows\ProPatches\"
            sRexe = """C:\windows\ProPatches\AgtInstallerX.exe"" /PW password"
      End If
      ' Change the cmd /k below to cmd /c to make the command prompt close
      ' after processing the command.  Leave it at /k for debugging.
      sCmd = "cmd /k " & strPSExecPath & " -accepteula -e -i " & sRexe
      ' Change the 1 below to 0 to make the command prompt hidden.
      ' Note: Do NOT use a zero here, with the /k switch above.
      ' That will cause a hidden, non-closing command prompt to be created.
      objShell.Run sCmd, 1, True
Next


Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ray Drummond

ASKER

Hi Rob.  Thanks for the response.  Trouble is, I'm still lost.  If you were to write the script from scratch, what would it look like?  The vbs file I have now has all this extra stuff in it that I don't know what it's doing.
Hey Rob....That worked.  I have a new problem now, but that's relatively simple.   You've helped me with the hard part.  Thanks.
Oh great.  Sorry I didn't get back to you earlier....glad you figured it out though. Well done.

Regards,

Rob.