www.pudn.com > shellwat.zip > SHELLWAT.FRM
VERSION 4.00
Begin VB.Form Form1
Caption = "ShellWat sample by Matt Hart - mhart@taascforce.com"
ClientHeight = 1440
ClientLeft = 1140
ClientTop = 1515
ClientWidth = 6405
Height = 1845
Left = 1080
LinkTopic = "Form1"
ScaleHeight = 1440
ScaleWidth = 6405
Top = 1170
Width = 6525
Begin VB.CommandButton Command1
Caption = "Start Notepad"
Height = 435
Left = 1860
TabIndex = 0
Top = 840
Width = 2415
End
Begin VB.Label Label1
Caption = "Click the button below to open a Notepad window. When you close Notepad, the MsgBox ""Process Finished!"" will pop up."
Height = 495
Left = 180
TabIndex = 1
Top = 60
Width = 5955
End
End
Attribute VB_Name = "Form1"
Attribute VB_Creatable = False
Attribute VB_Exposed = False
Option Explicit
' ShellWat sample by Matt Hart - mhart@taascforce.com
' http://www.webczar.com/defcon/mh/vbhelp.html
' http://www.webczar.com/defcon/mh
'
' Shows how to shell to another program, and wait until it finishes
' before continuing.
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Private Const INFINITE = -1&
Private Const SYNCHRONIZE = &H100000
Private Sub Command1_Click()
Dim iTask As Long, ret As Long, pHandle As Long
iTask = Shell("notepad.exe", vbNormalFocus)
pHandle = OpenProcess(SYNCHRONIZE, False, iTask)
ret = WaitForSingleObject(pHandle, INFINITE)
ret = CloseHandle(pHandle)
MsgBox "Process Finished!"
End Sub