Ray Drummond
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 \agtinstal lerx.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\Agt InstallerX .exe /PW password"""
Else
sDest = "\\" & sLine & "\c$\windows\ProPatches\"
sRexe = """C:\windows\ProPatches\A gtInstalle rX.exe /PW password!"""
End If
Would greatly appreciate the help.
c:\%systemroot%\propatches
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\Agt
Else
sDest = "\\" & sLine & "\c$\windows\ProPatches\"
sRexe = """C:\windows\ProPatches\A
End If
Would greatly appreciate the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
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.
Regards,
Rob.
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.Fi
Set objShell = CreateObject("WScript.Shel
' Specify your path to the PSExec executable
' so you can get the short path to it
strPSExecPath = "C:\Tools\PSExec.exe"
strPSExecPath = FileSystem.GetFile(strPSEx
For Each sLine In aComp
'WScript.Echo sLine
If FileSystem.FolderExists ("\\" & sLine & "\c$\winnt") Then
sDest = "\\" & sLine & "\c$\winnt\ProPatches\"
sRexe = """C:\winnt\ProPatches\Agt
Else
sDest = "\\" & sLine & "\c$\windows\ProPatches\"
sRexe = """C:\windows\ProPatches\A
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.