How to pass the DOS commands directly and output the results to a file.
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 'System & API - How to pass the DOS commands directly and output the results to a file. 'This example will pass the DIR command, enter C:\, and output the directory 'listing to the file C:\Dir.txt The /K switch is to keep the DOS window open but 'you can change it to the /C to close it. Also, SW_HIDE to make it totally 'transparent to the user. 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_HIDE As Long = 0 Private Const SW_SHOWNORMAL As Long = 1 Private Sub Command1_Click() ShellExecute Me.hwnd, "Open", "C:\Windows\System32\CMD.exe", _ " /K Dir C:\ > C:\Dir.txt", "C:\", SW_SHOWNORMAL End Sub 'Note: you would want to use the GetSystemDirectory API to dynamically get the 'directory where the CMD.EXE program is located. |