Forum Discussion

ChrisPro's avatar
ChrisPro
Contributor
12 years ago

WScript.Shell without dos screen

I run a command with following code :

            var WScriptObj = Sys.OleObject("WScript.Shell");

            var ExecOperation = WScriptObj.Exec("........");




But a dos window is displayed.



Is it possible to not display dos window when the command is executed?

9 Replies

  • Exec always shows the console window.



    But if you don't need to access StdIn/StdOut/StdErr streams, you can use Run. It hides the console window if you set the 2nd parameter to 0:



    var WScriptObj = Sys.OleObject("WScript.Shell");



    // Run the command and wait for completion

    WScriptObj.Run("...", 0, true);



    // Run the command but don't wait for completion

    WScriptObj.Run("...", 0, false);

  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Chris,



    As Helen wrote, setting third parameter to True delays script execution until the called command completes :


    > // Run the command and wait for completion


    > WScriptObj.Run("...", 0, true);

  • AlexKaras's avatar
    AlexKaras
    Community Hero
    What is not possible?

    You can check the return (exit) code, but there is no need in timeout as by design the method waits until the called command completes.

    If you need a timeout, you may call .Run asynchroniously (using its third parameter) and then check in a loop if the command completed and terminate the started process if timeout expired.



    BTW, may I wonder why it is so critical that DOS window must be not visible in the test?