Link to home
Start Free TrialLog in
Avatar of itnifl
itniflFlag for Norway

asked on

Can start powershell script from vbs but not from vbe

In short this is the code that runs another powershell script:

sAppCmd = "powershell -noexit &'" & ps1Name & "' '" & sUserName & "'"
Wscript.Echo "Running " & sAppCmd
oShell.Run sAppCmd, 4, false
Wscript.Quit 0

Open in new window


There are no loops here. If the script is in its vbs form, then it runs all nice and dandy. Executes the powershell script and then quits the vbs script. However, if I encode the vbs script to vbe, this all changes. The behaviour is that the vbe executes the powershell but not the powershell script, then the vbe script quits, but before that it restarts in a new window and continues to loop this behaviour until I hit Ctrl-C. Both the vbs and the vbe script are the same code, only difference is that the vbe script is encrypted with Windows Script Encoder. If I comment away line number three and re-encode to vbe, the vbe script will not loop this same way. It almost looks like the vbe version is not to happy to have to deal with oShell.Run and/or the arguments given to it.

Any suggestion for a remedy?
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, it works fine for me on Windows 7.  I had this in my VBS (and only this, nothing more):
Set objShell = CreateObject("WScript.Shell")
strPS1File = "C:\Temp\Scripts\TestPS1.ps1"
strArg = "hi"
objShell.Run "powershell -noexit &'" & strPS1File & "' '" & strArg & "'", 1, True

Open in new window


And I encoded it using this command:
screnc C:\temp\scripts\testvbs1.vbs c:\temp\scripts\testvbs1.vbe

and after double-clicking the VBE it worked fine.  I'm not sure why yours would have an issue.....

Do you have any odd characters in your arguments?  Does it make a difference if you remove spaces from the PS1 path?

Regards,

Rob.
Avatar of itnifl

ASKER

No odd arguments, just what is intended. Have tried to use a PS1 path without spaces.
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