• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

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?
  • 2
1 Solution
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?


itniflAuthor Commented:
No odd arguments, just what is intended. Have tried to use a PS1 path without spaces.
Are you running the script from an Administrator command prompt?  Run cmd.exe "As Administrator", then type
cscript C:\Scripts\MyScript.vbe
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now