Library code snippets
Running a DOS command
Occasionally you might find that you want to run a dos command from your VB program. The easiest way to do this is create a batch file (*.bat) containing the command (ie registering a number of components). Your program can then call this file, and wait until it has finished using the code below
Private Sub cmdDos_Click()
Dim lngTask As Long, lRet As Long, pHandle As Long
'// start the dos program
lngTask = Shell(App.Path & "pointless.bat",
vbMinimizedNoFocus)
'// get a handle on the window
pHandle = OpenProcess(SYNCHRONIZE, False, lngTask)
lblStatus.Caption = "Running DOS program..."
lblStatus.Refresh
cmdDOS.Enabled = False
Do
'// you can pass INFINITE instead
of 0 if you wish, and your
'// program will 'hang' here until
the program is finished
lRet = WaitForSingleObject(pHandle,
0)
DoEvents
Loop While lRet <> 0
lblStatus.Caption = "Finished"
lRet = CloseHandle(pHandle) 'Close the task
cmdDOS.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
If cmdNotepad.Caption = "Close Notepad" Then Call
cmdNotepad_Click
End Sub
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
The example code uses a function: OpenProcess
I cannot find out where, or how to use, this function
This thread is for discussions of Running a DOS command.