Results 1 to 5 of 5

Thread: How to run a command at cmd line?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Princeton, New Jersey
    Posts
    46

    Post

    I am very new to VB. In VBscript, I am able to run commands (regsvr32.exe /s /c ... regedit -s ... net stop... etc.) in a hidden cmd.exe window using WSH and creating a ("wscript.shell") object and passing whatever the command is to a little sub.

    How can I run a program like cmd.exe in a hidden window and wait till it finishes execution to return to the VB app? (I need to stop services, register Dlls, and install registry keys.) Thanks.

  2. #2
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Galway, Ireland
    Posts
    316

    Post

    Got this from the help hope this is what you want.

    [email protected]
    Co Galway, Ireland

    ' In Microsoft Windows:
    ' Specifying 0 as the second argument opens the application in
    ' hidden size and gives it the focus.

    RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' Run Calculator.

    Here are the constants
    Constant Value Description

    vbHide 0
    Window is hidden and focus is passed to the hidden window.

    vbNormalFocus 1
    Window has focus and is restored to its original size and position.

    vbMinimizedFocus 2
    Window is displayed as an icon with focus.

    vbMaximizedFocus 3
    Window is maximized with focus.

    vbNormalNoFocus 4
    Window is restored to its most recent size and position. The currently active window remains active.

    vbMinimizedNoFocus 6
    Window is displayed as an icon. The currently active window remains active.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Princeton, New Jersey
    Posts
    46

    Post

    Thanks for the reply! That helps me out very much.

    Another quick question for anyone...
    Would anyone know how to pass a command to the external program?

    --Say you wanted to stop the Alerter service in NT and you wanted to run "net stop "Alerter" from the command prompt in a hidden command window.

    --How could you pass "net stop Alerter" to
    Shell("cmd.exe" , 0) ??

    Thanks for any thoughts on this!

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Princeton, New Jersey
    Posts
    46

    Post

    In case anybody cares....
    You can use:
    Shell("cmd.exe /c <whatever command you want to run from a command prompt here>")
    To send a command to cmd.exe...

    Example:

    Shell("cmd.exe /c net stop w3svc")

    (to stop web publishing service)

    Im sure this is the clunkiest way to do this, but what do I know? <nothing>

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Manchester
    Posts
    446
    Is it possible to track thethreads of this?
    "Life isn't about finding yourself. Life is about creating yourself."
    --George Bernard Shaw

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width