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);
if EnablePrivilege(hToken, 'SeDebugPrivilege', True) then ShowMessage('OK');
CloseHandle(hToken);
end;function KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
beginResult := 0;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);FProcessEntry32.dwSize := SizeOf(FProcessEntry32);ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);while Integer(ContinueLoop) <> 0 dobeginif ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) thenResult := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);end;CloseHandle(FSnapshotHandle);end;以下为要改的。我老写不对。目的是对比出不要的程序并杀死。
procedure TForm1.Button41Click(Sender: TObject);
var
i: Integer;
j: STRING;
begin
begin
for i := 0 to l.Count-1 do
begin
j:=pProcessInfo(l.Items[i]).ExeFile;
begin
begin
if
j <> 'KERNEL32.DLL' then
begin
if
j <> 'msgsrv32.exe' then
begin
if
j <> 'explorer.exe' then
begin
if
j <> 'rundll32.exe' then
begin
if
j <> 'internat.exe' then
begin
if
j <> 'mprexe.exe' then
begin
if
j <> 'mmtask.tsk' then
begin
KillTask(j);
ListBox1.Items.Add(j);
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
showmessage('ok');
end;
大家帮忙拉
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);
if EnablePrivilege(hToken, 'SeDebugPrivilege', True) then ShowMessage('OK');
CloseHandle(hToken);
end;function KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
beginResult := 0;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);FProcessEntry32.dwSize := SizeOf(FProcessEntry32);ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);while Integer(ContinueLoop) <> 0 dobeginif ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) thenResult := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);end;CloseHandle(FSnapshotHandle);end;以下为要改的。我老写不对。目的是对比出不要的程序并杀死。
procedure TForm1.Button41Click(Sender: TObject);
var
i: Integer;
j: STRING;
begin
begin
for i := 0 to l.Count-1 do
begin
j:=pProcessInfo(l.Items[i]).ExeFile;
begin
begin
if
j <> 'KERNEL32.DLL' then
begin
if
j <> 'msgsrv32.exe' then
begin
if
j <> 'explorer.exe' then
begin
if
j <> 'rundll32.exe' then
begin
if
j <> 'internat.exe' then
begin
if
j <> 'mprexe.exe' then
begin
if
j <> 'mmtask.tsk' then
begin
KillTask(j);
ListBox1.Items.Add(j);
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
end;
showmessage('ok');
end;
大家帮忙拉
解决方案 »
- 数字操作的一个小问题
- 用fastreport解决一个自动换页的问题(在线急等)
- 这是一个其它地方常见的钩子程序,为什么不能正确运行?请帮忙看看
- 用存储过程或INSERT或UPDATE将文件流以二进制方式存到SQL SERVER 的IMAGE字段。
- 关于字段跟delphi不相兼容的问题,很难很难
- 如何将Dbcheckbox植入Dbgrid中?
- 我的Delphi环境怎么了,怎么总是出错呢!
- 简单问题(先来先拿分,在线)
- 急,主从表操作中,从表新加记录有错误
- gsm610转pcm后有杂音,什么原因?
- 用什么程序打开csdn邮件期刊?
- 怎样把24bit bmp,ico,wav封装在dll中,在程序中如何调用
pf
你用一个列表搞个循环,用的着用这么多if 来判断吗
不用这么多if吧?
你把要杀的进程名写到一个List中,然后对比一下,
if LixtBox1.Items.Indexof(pro_name) > 0 then
KillIt(abc);
这样代码就简洁一点了。
const
ExceptStr = ',KERNEL32.DLL,msgsrv32.exe,explorer.exe,rundll32.exe,'+
'internat.exe,mprexe.exe,mmtask.tsk,';
var
i: Integer;
j: STRING;
begin
for i := 0 to l.Count-1 do
begin
j:=pProcessInfo(l.Items[i]).ExeFile;//最长只有11位,Windows2000下
if Pos(','+j, ExceptStr) < 1 then
begin
KillTask(j);
ListBox1.Items.Add(j);
end;
end;
showmessage('ok');
end;
const
ExceptStr = ',KERNEL32.DLL,msgsrv32.exe,explorer.exe,rundll32.exe,'+
'internat.exe,mprexe.exe,mmtask.tsk,';
var
i: Integer;
j: STRING;
begin
for i := 0 to l.Count-1 do
begin
j:=ExtractFileName(pProcessInfo(l.Items[i]).ExeFile);//这样修改才能适应98和2000
if Pos(','+j, ExceptStr) < 1 then
begin
KillTask(j);
ListBox1.Items.Add(j);
end;
end;
showmessage('ok');
end;
j:=ExtractFileName(pProcessInfo(l.Items[i]).ExeFile);//这样修改才能适应98和2000
就是这里写错了。