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.   


  3. #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

  4. #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

  5. #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

  6. #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
Execute vbscript using cscript.exe on remote machine using Powershell PowerShell
execute mysql query using vbscript VB Script
Execute VBScript from a floating popup menu VB Script
Execute error: Type Mismatch: 'Execute' VB Script
vbscript and UAC prompt Vista General