-
Delphi 中关闭指定进程的方法
- Uses
- Windows,
- SysUtils,
- Tlhelp32 ;
-
- Function KillTask( ExeFileName: String ): Integer ;
- Function EnableDebugPrivilege: Boolean ;
- Function FindProcessId( ExeFileName: String ): THandle ;
-
- Implementation
-
- Function FindProcessId( ExeFileName: String ): THandle ;
- Var
- ContinueLoop: BOOL ;
- FSnapshotHandle: THandle ;
- FProcessEntry32: TProcessEntry32 ;
- Begin
- result := 0 ;
- FSnapshotHandle := CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ;
- FProcessEntry32.dwSize := Sizeof( FProcessEntry32 ) ;
- ContinueLoop := Process32First( FSnapshotHandle, FProcessEntry32 ) ;
- While integer( ContinueLoop ) <> 0 Do
- Begin
- If UpperCase( FProcessEntry32.szExeFile ) = UpperCase( ExeFileName ) Then
- Begin
- result := FProcessEntry32.th32ProcessID ;
- break ;
- End ;
- ContinueLoop := Process32Next( FSnapshotHandle, FProcessEntry32 ) ;
- End ;
- CloseHandle( FSnapshotHandle ) ;
- End ;
-
- Function KillTask( ExeFileName: String ): Integer ;
- Const
- PROCESS_TERMINATE = $0001 ;
- Var
- ContinueLoop: boolean ;
- FSnapshotHandle: THandle ;
- FProcessEntry32: TProcessEntry32 ;
- Begin
- Result := 0 ;
- FSnapshotHandle := CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ;
- FProcessEntry32.dwSize := SizeOf( FProcessEntry32 ) ;
- ContinueLoop := Process32First( FSnapshotHandle, FProcessEntry32 ) ;
-
- While Integer( ContinueLoop ) <> 0 Do
- Begin
- If ( ( UpperCase( ExtractFileName( FProcessEntry32.szExeFile ) ) =
- UpperCase( ExeFileName ) ) Or ( UpperCase( FProcessEntry32.szExeFile ) =
- UpperCase( ExeFileName ) ) ) Then
- Result := Integer( TerminateProcess(
- OpenProcess( PROCESS_TERMINATE,
- BOOL( 0 ),
- FProcessEntry32.th32ProcessID ),
- 0 ) ) ;
- ContinueLoop := Process32Next( FSnapshotHandle, FProcessEntry32 ) ;
- End ;
- CloseHandle( FSnapshotHandle ) ;
- End ;
-
-
-
- Function EnableDebugPrivilege: Boolean ;
-
- Function EnablePrivilege( hToken: Cardinal ;PrivName: String ;bEnable: Boolean ): Boolean ;
- Var
- TP: TOKEN_PRIVILEGES ;
- Dummy: Cardinal ;
- Begin
- TP.PrivilegeCount := 1 ;
- LookupPrivilegeValue( Nil, pchar( PrivName ), TP.Privileges[ 0 ].Luid ) ;
- If bEnable Then
- TP.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED
- Else
- TP.Privileges[ 0 ].Attributes := 0 ;
- AdjustTokenPrivileges( hToken, False, TP, SizeOf( TP ), Nil, Dummy ) ;
- Result := GetLastError = ERROR_SUCCESS ;
- End ;
- Var
- hToken: Cardinal ;
- Begin
- OpenProcessToken( GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, hToken ) ;
- result := EnablePrivilege( hToken, 'SeDebugPrivilege', True ) ;
- CloseHandle( hToken ) ;
- End ;
-
- End.
-
-
相关阅读:
mock.js
v-bind和v-model的区别
if语句中的return
js中全局变量和局部变量以及变量声明提升
js中全局和局部变量的区别
相对路径、绝对路径
commonJs
B/S与C/S
background-origin
DOM
-
原文地址:https://www.cnblogs.com/wxb-km/p/3461390.html
Copyright © 2020-2023
润新知