run dos commands thru VB?
-
I want to run DOS commands thru a VB app? I know that I can use Shell, but is there a better way? /Jarek
-
Its in VB6, I can't get it to work properly? this is my test code, this code actualy openes upp 3 cmd's and show the dir in the last one? I only want one cmd and be able to run different commands in it! There is a second problem cmd only works in W2K, NT and XP but not in WIN95-98, there got to be a way to run commands?
Shell "cmd", 1 SendKeys "dir c:\ *.txt" + Chr(13), True
-
Its in VB6, I can't get it to work properly? this is my test code, this code actualy openes upp 3 cmd's and show the dir in the last one? I only want one cmd and be able to run different commands in it! There is a second problem cmd only works in W2K, NT and XP but not in WIN95-98, there got to be a way to run commands?
Shell "cmd", 1 SendKeys "dir c:\ *.txt" + Chr(13), True
Where to start... OK. There are 2 command prompt shells in WinNT and above, CMD and COMMAND. 95/98 only has COMMAND. Now, what you want to do by stuffing the keystrokes using SendKeys is problematic at best. This is because there is no facility to make sure that, when you start the command shell, that window retains the input focus. Another window can steal the focus or the user can click in a different window. On top of that, what if the user accidentally types something in the command window your launched? I would HIGHLY recommend looking into the Win32 Console API's, especially if you want to keep reusing the same command windows. This way, you don't have to worry about Windows versioning problems either. The docs for the Console start here[^]. A word of warning though, the documentation is written for C++ and not VB. RageInTheMachine9532
-
Where to start... OK. There are 2 command prompt shells in WinNT and above, CMD and COMMAND. 95/98 only has COMMAND. Now, what you want to do by stuffing the keystrokes using SendKeys is problematic at best. This is because there is no facility to make sure that, when you start the command shell, that window retains the input focus. Another window can steal the focus or the user can click in a different window. On top of that, what if the user accidentally types something in the command window your launched? I would HIGHLY recommend looking into the Win32 Console API's, especially if you want to keep reusing the same command windows. This way, you don't have to worry about Windows versioning problems either. The docs for the Console start here[^]. A word of warning though, the documentation is written for C++ and not VB. RageInTheMachine9532
Thank you! I am a C++ programmer ;) I know the console API. In STL C++ you can use system function but not in VB :( It amazes me that there is no other way to run console commands in VB? /Jarek As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality. Albert Einstein
-
Thank you! I am a C++ programmer ;) I know the console API. In STL C++ you can use system function but not in VB :( It amazes me that there is no other way to run console commands in VB? /Jarek As far as the laws of mathematics refer to reality, they are not certain; and as far as they are certain, they do not refer to reality. Albert Einstein
VB6 didn't really have a console available to it. VB.NET has much better support. If all you want to do is launch other programs, use the Shell, but your Shell command can also include it's command line parameters. You don't have to stuff them in with SendKeys... RageInTheMachine9532