Can start powershell script from vbs but not from vbe

Posted on 2012-08-31
Medium Priority
Last Modified: 2012-09-27
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?
Question by:itnifl
  • 2
LVL 65

Expert Comment

ID: 38359644
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?



Author Comment

ID: 38407961
No odd arguments, just what is intended. Have tried to use a PS1 path without spaces.
LVL 65

Accepted Solution

RobSampson earned 2000 total points
ID: 38407988
Are you running the script from an Administrator command prompt?  Run cmd.exe "As Administrator", then type
cscript C:\Scripts\MyScript.vbe

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question