none
executing a vb script ... RRS feed

  • Question

  • I am new to vb script programming. I have a vb script which i saved with .vbs extension. The script is working fine but while execution DOS screen appears. earlier when i used to execute it no such screen appeared . I have also encountered that when right click on the vb script icon it shows 'open with command prompt' on top of the list instead 'Open', Please help me to find a solution. I do not want command prompt to appear on my Screen.
    Saturday, April 21, 2012 6:23 PM

Answers

  • I suspect that the OP is talking about the symptoms of having the scripts run under the cscript.exe host as opposed to the more common situation of the Wscript.exe being the default host.  Since cscript.exe is a console application, it opens a console window while the script is executing.  The console window closes immediately following the script's completion, thus causing the 'flash' effect.

    I'd suggest running wscript of cscript with its //h:WSCRIPT switch to force the GUI Wscript.exe host to be the default.  Either at the command prompt or via the Start/Run dialog, type ...

      wscript //h:WSCRIPT

    That should fix things.  If it doesn't, the OP will need to explain his circumstances further.


    Tom Lavedas

    Sunday, April 22, 2012 2:35 PM
    Moderator

All replies

  • I am new to vb script programming. I have a vb script which i saved with .vbs extension. The script is working fine but while execution DOS screen appears. earlier when i used to execute it no such screen appeared . I have also encountered that when right click on the vb script icon it shows 'open with command prompt' on top of the list instead 'Open', Please help me to find a solution. I do not want command prompt to appear on my Screen.

    We cannot be of much help without a copy of your script.

    'Open with command prompt' is the normal top command and is not what is causing the problem.

    Go to command prompt and run teh sript.  Look at the error message and fix the error then the console will not display.

    To prove that create and run the following simple test:

    'file test.vbs
    WScript.Echo " Hello World!"
    WScript.Sleep 30000
    ' end of file

    It will run, display meassage then wait for 30 seconds and close. Be very careful to copy it exactly as it is.


    ¯\_(ツ)_/¯

    Saturday, April 21, 2012 6:51 PM
  • I suspect that the OP is talking about the symptoms of having the scripts run under the cscript.exe host as opposed to the more common situation of the Wscript.exe being the default host.  Since cscript.exe is a console application, it opens a console window while the script is executing.  The console window closes immediately following the script's completion, thus causing the 'flash' effect.

    I'd suggest running wscript of cscript with its //h:WSCRIPT switch to force the GUI Wscript.exe host to be the default.  Either at the command prompt or via the Start/Run dialog, type ...

      wscript //h:WSCRIPT

    That should fix things.  If it doesn't, the OP will need to explain his circumstances further.


    Tom Lavedas

    Sunday, April 22, 2012 2:35 PM
    Moderator
  • I have XP running on virtual box... and there also i have a vbscript:

    msgbox "this is Vb script"    

    (just one line only)

    and upon right clicking it shows 'Open' @ the top of the list and 'Open with command Prompt' on third position.
    i have screen shots for you to get what exactly is going wrong..
    1.) this is on XP (Virtual machine)


    2.)
         I have created a huge mess. All the vb scripts icons are changed. when i chose the option 'open with'.. wscript present in system32..pllease help me to sort it out.
     you can see on the list 'open with cmd prompt'... which was not there earlier. That option used to be at the third position.

    Monday, April 23, 2012 5:29 AM

  • Thank you so much for your assistance Mr Tom...

    but i have more thing...which went wrong. I selected the option 'open With' and browsed, and in the System32 Folder i selected the application 'Wscript', hence the by default icon appearance of a vb script has changed with.. that of 'wscipt'...  cube like icons.. can you suggest me a method to fix it. ?

    i have a screen shot ...

    Monday, April 23, 2012 5:43 AM
  • I am sorry but you need to follwo my instructions or we will be going around in circles.

    Tom's suggestin would be correct, but, it seems that you have other issues including a lack of knowledge of the Windows comand prompt.

    Open a command prompt by choosing 'Run' from thr 'Start' menu and type  'CMD' and click OK.

    Navigate to the folder5 whert eyou script is kept.  Remember this is not with the GUI but is with a CMD prompt..

    Type the name of your script and watch what is printed on the console.  This will tell you what is happening so it can be fixed.

    Once you have reported the result of this soemone will give you insructions on what to type to fix your associations.

    When you save a script fromnotepad you must type teh script name and its extension and surround that with quotes.  Like this "test.vbs".

    This will prevent the file from having the default txt extension.


    ¯\_(ツ)_/¯


    • Edited by jrv Monday, April 23, 2012 8:21 AM
    Monday, April 23, 2012 8:18 AM
  • By the way. On all  of my XP systems the 'Open with command prompt' is on top and the 'Open' command is the third item.  Any script tat is very short with minimal output wil just flash a box.  This is  normal behavior for cscript.  Tom' suggestion was intended to force the output to show in message boxes on teh screen assuming there are messages.  If no messages you will not get anything.

    To use Tom's suggestion you need to go to a command prompt an type the comamnds he asked you to type.  You cannot run his commands from the GUI.

    If you are stillconfused about this here are some easy instructions.

    http://www.youtube.com/watch?v=X3NtiEbNe-c


    ¯\_(ツ)_/¯

    Monday, April 23, 2012 8:32 AM
  • This will also be helpful in understanding what is happening:

    http://technet.microsoft.com/library/ee176996.aspx


    ¯\_(ツ)_/¯

    Monday, April 23, 2012 8:35 AM