home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD6454652000.psc / ShellWait.bas < prev    next >
Encoding:
BASIC Source File  |  2000-06-05  |  1.9 KB  |  64 lines

  1. Attribute VB_Name = "ShellWait"
  2. Option Explicit
  3.  
  4. Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
  5.  As Long) As Long
  6. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  7. Private Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal _
  8.  lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal _
  9.  lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
  10.  ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
  11.  ByVal lpCurrentDirectory As Long, lpStartupInfo As _
  12.  STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
  13.  
  14. Private Type STARTUPINFO
  15.     cb As Long
  16.     lpReserved As String
  17.     lpDesktop As String
  18.     lpTitle As String
  19.     dwX As Long
  20.     dwY As Long
  21.     dwXSize As Long
  22.     dwYSize As Long
  23.     dwXCountChars As Long
  24.     dwYCountChars As Long
  25.     dwFillAttribute As Long
  26.     dwFlags As Long
  27.     wShowWindow As Integer
  28.     cbReserved2 As Integer
  29.     lpReserved2 As Long
  30.     hStdInput As Long
  31.     hStdOutput As Long
  32.     hStdError As Long
  33. End Type
  34.  
  35. Private Type PROCESS_INFORMATION
  36.     hProcess As Long
  37.     hThread As Long
  38.     dwProcessID As Long
  39.     dwThreadID As Long
  40. End Type
  41.  
  42. Private Const NORMAL_PRIORITY_CLASS = &H20&
  43. Private Const INFINITE = -1&
  44. Public TaskID As Long
  45. Public Function ExecuteTask(cmdline As String) As Long
  46. Dim proc As PROCESS_INFORMATION
  47. Dim startup As STARTUPINFO
  48. Dim ret As Long
  49. startup.cb = Len(startup)
  50. ret = CreateProcessA(0&, cmdline, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, startup, proc)
  51. ExecuteTask = proc.hProcess
  52. End Function
  53. Public Function TaskRunning() As Boolean
  54. Dim ret As Long
  55. If TaskID = 0 Then Exit Function
  56. ret = WaitForSingleObject(TaskID, 0)
  57. TaskRunning = (ret <> 0)
  58. If Not TaskRunning Then
  59. ret = CloseHandle(TaskID)
  60. TaskID = 0
  61. End If
  62. End Function
  63.  
  64.