VB利用进程句柄挂起恢复进程
2007-09-30 14:16
204 查看
VERSION 5.00
Begin VB.Form frmMain
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdTerminate
Caption = "终止该进程"
Height = 375
Left = 3240
TabIndex = 3
Top = 1920
Width = 1335
End
Begin VB.CommandButton cmdClose
Caption = "关闭句柄"
Height = 495
Left = 1920
TabIndex = 2
Top = 1800
Width = 1335
End
Begin VB.TextBox txtPid
Height = 495
Left = 720
TabIndex = 1
Text = "123"
Top = 480
Width = 1695
End
Begin VB.CommandButton cmdResume
Caption = "恢复进程"
Height = 495
Left = 120
TabIndex = 0
Top = 1800
Width = 1815
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Declare Function NtSuspendProcess Lib "ntdll.dll" (ByVal hProc As Long) As Long
Private Declare Function NtResumeProcess Lib "ntdll.dll" (ByVal hProc As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private hProcess As Long
Private Sub cmdClose_Click()
CloseHandle hProcess
End Sub
Private Sub cmdResume_Click()
If IsNumeric(txtPid.Text) Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, CLng(txtPid.Text))
If hProcess <> 0 Then
NtResumeProcess hProcess
End If
End If
End Sub
Private Sub cmdTerminate_Click()
If hProcess Then
TerminateProcess hProcess, 0
Else
If IsNumeric(txtPid.Text) Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, CLng(txtPid.Text))
If hProcess <> 0 Then
TerminateProcess hProcess, 0
End If
End If
End If
End Sub
Begin VB.Form frmMain
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdTerminate
Caption = "终止该进程"
Height = 375
Left = 3240
TabIndex = 3
Top = 1920
Width = 1335
End
Begin VB.CommandButton cmdClose
Caption = "关闭句柄"
Height = 495
Left = 1920
TabIndex = 2
Top = 1800
Width = 1335
End
Begin VB.TextBox txtPid
Height = 495
Left = 720
TabIndex = 1
Text = "123"
Top = 480
Width = 1695
End
Begin VB.CommandButton cmdResume
Caption = "恢复进程"
Height = 495
Left = 120
TabIndex = 0
Top = 1800
Width = 1815
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Declare Function NtSuspendProcess Lib "ntdll.dll" (ByVal hProc As Long) As Long
Private Declare Function NtResumeProcess Lib "ntdll.dll" (ByVal hProc As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private hProcess As Long
Private Sub cmdClose_Click()
CloseHandle hProcess
End Sub
Private Sub cmdResume_Click()
If IsNumeric(txtPid.Text) Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, CLng(txtPid.Text))
If hProcess <> 0 Then
NtResumeProcess hProcess
End If
End If
End Sub
Private Sub cmdTerminate_Click()
If hProcess Then
TerminateProcess hProcess, 0
Else
If IsNumeric(txtPid.Text) Then
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, CLng(txtPid.Text))
If hProcess <> 0 Then
TerminateProcess hProcess, 0
End If
End If
End If
End Sub
相关文章推荐
- VB 挂起和恢复进程
- MFC任务管理器task manager----进程的挂起与恢复--NtSuspendProcess&&NtResumeProcess
- UNIX/Linux 进程的挂起和恢复
- linux下挂起恢复进程
- C#中进程的挂起与恢复
- 进程的挂起及恢复
- Linux 进程的挂起和恢复
- linux进程的挂起及恢复
- win32程序如何挂起/恢复(suspend/resume)进程
- Linux中线程的挂起与恢复(进程暂停)
- Linux 的进程挂起和恢复
- 利用VB进行SQL2000的数据备份和恢复
- Linux 进程的挂起和恢复
- C 挂起和恢复进程
- MFC任务管理器task manager----进程的挂起与恢复--NtSuspendProcess&&NtResumeProcess
- 每天学点Linux--(进程的挂起与恢复)
- linux中线程的挂起与恢复(进程暂停)
- linux进程的挂起及恢复
- linux中线程的挂起与恢复(进程暂停)
- Linux 进程挂起、恢复相关命令