Can start powershell script from vbs but not from vbe

Posted on 2012-08-31
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
    LVL 65

    Expert Comment

    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?


    LVL 2

    Author Comment

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

    Accepted Solution

    Are you running the script from an Administrator command prompt?  Run cmd.exe "As Administrator", then type
    cscript C:\Scripts\MyScript.vbe

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
    In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now