none
Trying to run a vbscript using start-process fails RRS feed

  • Question

  • I have a powershell script that running and in it i try to run a vbscript to install some drivers.  I am using start-process to run it.  

    all it seems to do though is open a command prompt window running cscript.exe and then closes.  None of the vb script parameter gets passed to it.  Is this the wrong syntax or what am i doing wrong here?

    Start-Process -Filepath "cscript.exe" -ArgumentList "C:\My.vbs" -Verb runas


    Wednesday, May 1, 2019 8:27 PM

All replies

  • The command needs to be on one line not two.


    \_(ツ)_/

    Wednesday, May 1, 2019 9:15 PM
    Moderator
  • for some reason when i copied it it ended up like that, i am running it all as one line though 
    Wednesday, May 1, 2019 9:44 PM
  • Then it is throwing an error.  You need to find the error.


    \_(ツ)_/

    Wednesday, May 1, 2019 9:46 PM
    Moderator
  • Or run it like this:

    Start-Process -Filepath cscript.exe - ArgumentList C:\My.vbs -NoNewWindow   


    \_(ツ)_/

    Wednesday, May 1, 2019 9:48 PM
    Moderator
  • when i run it with -NoNewWindow a cmd prompt window still opens, it looks like its running just cscript.exe.  It sits there for a hadful of seconds then closes, i do not see any error come up in the window


    Wednesday, May 1, 2019 10:02 PM
  • What did you expect it to do?  If there is no output then that is what will happen.


    \_(ツ)_/

    Wednesday, May 1, 2019 10:12 PM
    Moderator
  • It should run the script which takes time to run, longer than 5 seconds. The vbscript should run an exe, which i never see running.  also ont the top bar of the command prompt window i should see what its running.  Should see "cscript c:\my.vbs"  which i dont, all i see is cscript like its not passing the argument list to cscript.exe

    Wednesday, May 1, 2019 10:18 PM
  • I may be assuming on the last statement, when i run it directly in command propmt then the top bar will show the file location its running, dont know it will do that when running it from start-process.  

    Wednesday, May 1, 2019 10:34 PM
  • You did not run the exact code I posted.  You changed it so it won't work.


    \_(ツ)_/

    Wednesday, May 1, 2019 10:34 PM
    Moderator
  • Run it like this so that you can trap errors and see any wscript.echo output.

    Start-Process -Filepath cscript.exe -ArgumentList C:\your.vbs -wait -RedirectStandardOutput c:\temp\vbs.out -RedirectStandardError c:\temp\vbs.err
    "-----VBS Complete----"
    "--------STDOUT-------"
    get-content c:\temp\vbs.out
    "--------STDERR-------"
    get-content c:\temp\vbs.err
       

     
    Thursday, May 2, 2019 1:02 AM
  • Thanks that seems very useful.  After successfully running it in my lab, i am of the opinion something is blocking it in the our environment.  Was confusing becuase it runs fine in cmd prompt so i thought my syntax was wrong.  thanks for all the help.  
    Thursday, May 2, 2019 2:07 PM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Lee


    Just do it.

    Friday, May 24, 2019 5:53 AM
    Moderator
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Friday, May 31, 2019 3:07 AM
    Moderator