Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I use dos command?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
howdy, I would like to use a dos command. example when I press a button, I would like it to envoke a dos console program along with commands.How do I do this?
 
Try the folloeing code in your button :
Code:
    Dim Dos
    Dos = Shell("Command.com", vbNormalFocus)

AC
 
Acron's suggestion will open a dos session, but if you want to run dos commands then you need to create a DOS batch file, then call the batch file from the shell() command.

I.E. shell("c:\my_batches\my_batch.bat")
 
OK Guys,

I tried this based on your suggestions and I cannot get it to work. Says it needs an object

Private Sub Command1_Click()

Dim DOS

DOS = Shell("cmd.exe", vbNormalFocus)

Shell ("d:\tester.bat")

End Sub
 
Fugly,

As ETID demonstrated, you need something like

Code:
Shell "d:\tester.bat", vbNormalFocus
or
Code:
Shell "cmd.exe /c d:\tester.bat", vbNormalFocus

Everything must be within the one Shell command.

You might want to use command.com in place of cmd.exe for backward compatiblity (cmd.exe is only available on NT-based systems and will not run 16-bit DOS programs).

Also, if you use only the path/filename of your batch file the DOS window remains after the batch file executes and must be closed manually. Use of the second syntax above allows the DOS session to terminate without intervention.

Kitty kat123,

You will probably need something like
Code:
Shell "command.com /c ProgramFilename /Optional Switches", vbMaximizedFocus

Hope this helps
M. Smith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top