Windows Vista Forums

How to execute dos cmds in the prompt opened using VBScript?

  1. #1


    AuHuman Guest

    How to execute dos cmds in the prompt opened using VBScript?

    Dim shell
    Dim oExec
    Set shell = CreateObject("wscript.shell")
    Set oExec = shell.Exec("cmd.exe")
    oExec.StdIn.Write("exit")
    oExec.StdIn.Write VbCrLf
    Do While oExec.Status = 0
    WScript.Sleep 100
    Loop
    WScript.Echo oExec.Status
    Above code is not executing the exit command in the command prompt opened by
    shell.Exec("cmd.exe").
    Nothing is happening until i close the prompt manually by clicking the close
    button.
    How to execute dos commands in the prompt opened by shell.Exec("cmd.exe") ?.
    [i looked into the msdn library but its not clearing my above doubt]

      My System SpecsSystem Spec

  2. #2


    Tom Lavedas Guest

    Re: How to execute dos cmds in the prompt opened using VBScript?

    On Jan 26, 3:09*pm, AuHuman <AuHu...@newsgroup> wrote:

    > Dim shell
    > Dim oExec
    > Set shell = CreateObject("wscript.shell")
    > Set oExec = shell.Exec("cmd.exe")
    > oExec.StdIn.Write("exit")
    > oExec.StdIn.Write VbCrLf
    > Do While oExec.Status = 0
    > WScript.Sleep 100
    > Loop
    > WScript.Echo oExec.Status
    > Above code is not executing the exit command in the command prompt openedby
    > shell.Exec("cmd.exe").
    > Nothing is happening until i close the prompt manually by clicking the close
    > button.
    > How to execute dos commands in the prompt opened by shell.Exec("cmd.exe")?.
    > [i looked into the msdn library but its not clearing my above doubt]
    This worked for me ...

    Dim shell, oExec
    Const delay = 5
    Set shell = CreateObject("wscript.shell")
    Set oExec = shell.Exec("cmd.exe /k echo Will close in " & delay & "
    second(s)>con")
    for n = delay to 1 step - 1
    WScript.Sleep 1000
    oExec.StdIn.Writeline "echo " & n & " > con"
    Next
    oExec.StdIn.Writeline "echo Closing > con"
    WScript.Sleep 1000
    oExec.StdIn.Writeline "exit"
    WScript.Echo oExec.Status
    _____________________
    Tom Lavedas

      My System SpecsSystem Spec

  3. #3


    AuHuman Guest

    Re: How to execute dos cmds in the prompt opened using VBScript?

    Thanks a lot Tom Lavedas. Your post showed me the right way of resolving the
    error i was facing.

    "Tom Lavedas" wrote:

    > On Jan 26, 3:09 pm, AuHuman <AuHu...@newsgroup> wrote:

    > > Dim shell
    > > Dim oExec
    > > Set shell = CreateObject("wscript.shell")
    > > Set oExec = shell.Exec("cmd.exe")
    > > oExec.StdIn.Write("exit")
    > > oExec.StdIn.Write VbCrLf
    > > Do While oExec.Status = 0
    > > WScript.Sleep 100
    > > Loop
    > > WScript.Echo oExec.Status
    > > Above code is not executing the exit command in the command prompt opened by
    > > shell.Exec("cmd.exe").
    > > Nothing is happening until i close the prompt manually by clicking the close
    > > button.
    > > How to execute dos commands in the prompt opened by shell.Exec("cmd.exe") ?.
    > > [i looked into the msdn library but its not clearing my above doubt]
    >
    > This worked for me ...
    >
    > Dim shell, oExec
    > Const delay = 5
    > Set shell = CreateObject("wscript.shell")
    > Set oExec = shell.Exec("cmd.exe /k echo Will close in " & delay & "
    > second(s)>con")
    > for n = delay to 1 step - 1
    > WScript.Sleep 1000
    > oExec.StdIn.Writeline "echo " & n & " > con"
    > Next
    > oExec.StdIn.Writeline "echo Closing > con"
    > WScript.Sleep 1000
    > oExec.StdIn.Writeline "exit"
    > WScript.Echo oExec.Status
    > _____________________
    > Tom Lavedas
    > .
    >

      My System SpecsSystem Spec

  4. #4


    mr_unreliable Guest

    Re: How to execute dos cmds in the prompt opened using VBScript?

    Tom Lavedas wrote:

    > This worked for me ...
    > ...
    > Set oExec = shell.Exec("cmd.exe /k echo Will close in " & delay & "
    > ...
    Suggest using:

    Set oExec = shell.Exec("%comspec% /k echo Will (blah, blah,.. )

    instead of:

    Set oExec = shell.Exec("cmd.exe /k echo Will (blah, blah,.. )


    cheers, nitpickers anonymous

      My System SpecsSystem Spec

  5. #5


    Tom Lavedas Guest

    Re: How to execute dos cmds in the prompt opened using VBScript?

    On Jan 31, 11:58*am, mr_unreliable
    <kindlyReplyToNewsgr...@newsgroup> wrote:

    > Tom Lavedas wrote:

    > > This worked for me ...
    > > ...
    > > Set oExec = shell.Exec("cmd.exe /k echo Will close in " & delay & "
    > > ...
    >
    > Suggest using:
    >
    > * *Set oExec = shell.Exec("%comspec% /k echo Will (blah, blah,.. )
    >
    > instead of:
    >
    > * *Set oExec = shell.Exec("cmd.exe /k echo Will (blah, blah,.. )
    >
    > cheers, nitpickers anonymous
    A nit picking Win98 user. I wonder how many of you there are
    left ;^))

    I always use COMSPEC, myself, but chose to stick with the formulation
    used by the OP in this case.
    _____________________
    Tom Lavedas

      My System SpecsSystem Spec

How to execute dos cmds in the prompt opened using VBScript?

Similar Threads
Thread Forum
are VBscript on Windows server 2003 and VBscript on WS2008 compatible?
Hi everybody, Sorry if my question has already been asked, but I haven't found anything which is clear for me on this point. I spent a lot of...
VB Script
Can a vbscript identify the program/process that called a vbscript
I would like to code a vbscript ("ActionScript.vbs") in such a way that it would do X, if ActionScript.vbs were called by "TriggerScriptA.vbs", but...
VB Script
Execute vbscript using cscript.exe on remote machine using Powershell
Hi everyone. I am pretty much out of ideas on how to remotely execute a vbscript that I placed on all of our servers using powershell. Here is the...
PowerShell
execute mysql query using vbscript
I have a script which will format some text and create a simple mysql query. The next thing I'd like the script to do is run a batch file to open...
VB Script
Execute VBScript from a floating popup menu
Please help, I am desperate! On my web html-php-mysql page, I use vbscript to execute method calls to an automation server (Dephi 7, apartment...
VB Script
Execute error: Type Mismatch: 'Execute'
Hello all, I'm in the process of writing a vbscript that uses KixForms as a GUI frontend. According to a number of web pages (and this group) it...
VB Script
vbscript and UAC prompt
Is there any way to force from inside a VBscript the UAC prompt? I have several vbscripts that run fine when launched from the elevated command...
Vista General