Instead of a batch file you can just pass the DOS commands directly. Then output the results to a file.
Its not that hard.
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.
Note: you would want to use the GetSystemDirectory API to dynamically get the directory where the CMD.EXE program is located.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_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
![]()





Reply With Quote