Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

  1. '//+----------------------------------------------------------------------------
  2. '//
  3. '// File: wait.bas
  4. '//
  5. '// Module: pbadmin.exe
  6. '//
  7. '// Synopsis: Wrapper functions to launch a process and wait for it to return.
  8. '//
  9. '// Copyright (c) 1997-1999 Microsoft Corporation
  10. '//
  11. '// Author: quintinb Created Header 09/02/99
  12. '//
  13. '//+----------------------------------------------------------------------------
  14. Attribute VB_Name = "wait"
  15. Option Explicit
  16. Private Const PROCESS_QUERY_INFORMATION = &H400
  17. Private Const STILL_ACTIVE = &H103
  18. Private Declare Function OpenProcess& Lib "kernel32" (ByVal _
  19. dwDesiredAccess&, ByVal bInheritHandle&, ByVal dwProcessId&)
  20. Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal _
  21. hProcess As Long, lpExitCode As Long) As Long
  22. Private Const IDC_UPARROW = 32516&
  23. ' GetWindow() Constants
  24. Public Const GW_HWNDFIRST = 0
  25. Public Const GW_HWNDLAST = 1
  26. Public Const GW_HWNDNEXT = 2
  27. Public Const GW_HWNDPREV = 3
  28. Public Const GW_OWNER = 4
  29. Public Const GW_CHILD = 5
  30. Public Const GW_MAX = 5
  31. Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
  32. Declare Function GetDesktopWindow Lib "user32" () As Long
  33. Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
  34. Public Function WaitForApp(sCmd As String) As Long
  35. Dim hApp As Long
  36. Dim hProc As Long
  37. Dim lExitCode As Long
  38. On Error GoTo WaitErr
  39. 'hApp = Shell(sCmd, vbNormalFocus)
  40. 'hApp = Shell(sCmd, vbHide)
  41. hApp = Shell(sCmd, vbMinimizedNoFocus)
  42. hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hApp)
  43. Do
  44. GetExitCodeProcess hProc, lExitCode
  45. DoEvents
  46. Loop While lExitCode = STILL_ACTIVE
  47. WaitForApp = lExitCode
  48. Exit Function
  49. WaitErr:
  50. Exit Function
  51. End Function
  52. Public Function GetWindowHandleFromProcessID(hProcessIDToFind As Long) As Long
  53. Dim hWindow As Long
  54. Dim bFoundIt As Boolean
  55. Dim hProcessIDToTest As Long
  56. Dim lRet As Long
  57. hWindow = GetWindow(GetDesktopWindow(), GW_CHILD)
  58. While hWindow <> 0
  59. hProcessIDToTest = 0
  60. lRet = GetWindowThreadProcessId(hWindow, hProcessIDToTest)
  61. If hProcessIDToTest = hProcessIDToFind Then
  62. bFoundIt = True
  63. GetWindowHandleFromProcessID = hWindow
  64. Exit Function
  65. End If
  66. hWindow = GetWindow(hWindow, GW_HWNDNEXT)
  67. DoEvents
  68. Wend
  69. GetWindowHandleFromProcessID = 0
  70. GetWindowHandleFromProcessID = -1
  71. End Function