hi guys,
is there anyway of sending dos commands to a dos prompt using vb? i don't want to execue a batch file using the shell function...this is not what i want. All i want is to send dos commands to the same dos session. plz help.
thanks,
zaf
Printable View
hi guys,
is there anyway of sending dos commands to a dos prompt using vb? i don't want to execue a batch file using the shell function...this is not what i want. All i want is to send dos commands to the same dos session. plz help.
thanks,
zaf
Once a Dos Shell is up and running Im not sure how you would pull that off, but I know you can call the command shell 1 time with another DOS command as an argument and it will run it for you once.
Easy enough. This works to do a CD and DIR and waits for an Enter to exit:-
Code:Sub test()
Enter = "~"
retval = Shell("c:\winnt\system32\cmd.exe", vbNormalFocus)
SendKeys "CD C:\TEMP" & Enter, True ' change folder
SendKeys "DIR" & Enter, True ' dir
SendKeys "EXIT". True
End Sub
Thanks guys, "sendkey" seems to have done the trick.
zaf
This is not DOS. Does this also work on a DOS prompt? DOS is run from Win9x like "Command.com", not "Cmd.exe".Quote:
Originally posted by BrianB
Easy enough. This works to do a CD and DIR and waits for an Enter to exit:-
Code:Sub test()
Enter = "~"
retval = Shell("c:\winnt\system32\cmd.exe", vbNormalFocus)
SendKeys "CD C:\TEMP" & Enter, True ' change folder
SendKeys "DIR" & Enter, True ' dir
SendKeys "EXIT". True
End Sub
i'm using command.com.
Cool, thanks. Can this work with the DOS window minimized?
the command prompt must have focus, else the text will not get printed in the dos prompt:
AppActivate "command.com" 'Command Prompt title bar
zaf
SendKeys - Arrrg! SendKeys is so flakey that if the user
accidentally changes the active application or presses a key, it
will throw SendKeys out of sync.
ShellExecute CDM.exe with parameters of what you want to pass or
execute in the DOS window.
Ex. this will create a text file of your c drive contents and close the
command window. This is very fast, better than using vb commands
to iterate through all the directories and out to a text file.
:)VB Code:
Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, _ ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Private Const SW_SHOWNORMAL As Long = 1 Private Const SW_SHOWMINIMIZED As Long = 2 Private Const SW_SHOWMAXIMIZED As Long = 3 Private Sub Command1_Click() Dim lRet As Long lRet = ShellExecute(0, "OPEN", "c:\winnt\system32\cmd.exe", "/C Dir >> C:\Dir_C.txt", "C:\", SW_SHOWNORMAL) End Sub
HTH