winapi: Ausführen eines Programms und Anhalten der aktuellen Anwendung

Mit diesem Code kann man ein Programm ausführen. Die aktuelle Anwendung wird dabei solange angehalten, bis das ausgeführte Programm beendet ist: 

  1. Public Type STARTUPINFO
  2. cb As Long
  3. lpReserved As String
  4. lpDesktop As String
  5. lpTitle As String
  6. dwX As Long
  7. dwY As Long
  8. dwXSize As Long
  9. dwYSize As Long
  10. dwXCountChars As Long
  11. dwYCountChars As Long
  12. dwFillAttribute As Long
  13. dwFlags As Long
  14. wShowWindow As Integer
  15. cbReserved2 As Integer
  16. lpReserved2 As Long
  17. hStdInput As Long
  18. hStdOutput As Long
  19. hStdError As Long
  20. End Type
  21. Public Type PROCESS_INFORMATION
  22. hProcess As Long
  23. hThread As Long
  24. dwProcessID As Long
  25. dwThreadID As Long
  26. End Type
  27. Declare Function WaitForSingleObject Lib "kernel32" (Byval _
  28. hHandle As Long, Byval dwMilliseconds As Long) As Long
  29. Declare Function CreateProcessA Lib "kernel32" (Byval _
  30. lpApplicationName As Long, Byval lpCommandLine As String, Byval _
  31. lpProcessAttributes As Long, Byval lpThreadAttributes As Long, _
  32. Byval bInheritHandles As Long, Byval dwCreationFlags As Long, _
  33. lpStartupInfo As STARTUPINFO, lpProcessInformation As _
  34. PROCESS_INFORMATION) As Long
  35. Declare Function CloseHandle Lib "kernel32" (Byval _
  36. hObject As Long) As Long
  37. Public Sub ShellAndWait(Byval RunProg As String)
  38. Dim RetVal As Long
  39. Dim proc As PROCESS_INFORMATION
  40. Dim StartInf As STARTUPINFO
  41. StartInf.cb = Len(StartInf)
  42. RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, _
  43. NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
  44. RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
  45. RetVal = CloseHandle(proc.hProcess)
  46. End Sub
 
 
© onvice 2002 - 2010