How to run a command of MS DOS with code through visual basic 6.0
for ex. setting the path, zip and unzip files etc.
and also the commands of Visual Foxpro Databasese through VB.

Recommended Answers

All 6 Replies

Dim oWSH
Dim cmdDOS As String
Set oWSH = CreateObject("WScript.Shell")
cmdDOS = "cmd.exe /c "
cmdDOS = cmdDOS & "DIR *.*"
oWSH.Run cmdDOS, 1
'Change the 1 to 0 if you don't want to see the dos window
shell "cmd.exe /c dir \"
commented: Very cool one command line +1
shell "cmd.exe /c dir \"

Could not you find a shorter one? :D

Nice Code

What if I need solution which opens cmd and then I need to send command to it, wait for it to be done, pick results and tings like that, but more than once? I think it's stupid to open and close every time whit shell. Is there smarter solution?
I would appreciate any kind of help. Thanks

Sashka, please read our posting rules. This is a very old post that has just been raised from the dead. This is however your first post, so no harm no foul.

Shell is still the shortest and quickest route to interact with cmd. Read the link belkow for more options on how to only minimize and not close cmd, how to send different commands etc stc.

Hope this puts you on the right track...

http://msdn.microsoft.com/en-us/library/d5fk67ky
This is also a nice one with plenty code samples using cmd...

http://www.dreamincode.net/forums/topic/17098-running-command-prompt-in-

Samir Ibrahim,
Thanks for the solution. It's a big help to me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.