在Windows 2K下,使用任务管理器结束进程Explorer.exe,然后点击新任务
按钮,重新运行Explorer.exe,这个过程用代码的方式如何实现?望不吝赐教,多谢!!
ePing
按钮,重新运行Explorer.exe,这个过程用代码的方式如何实现?望不吝赐教,多谢!!
ePing
解决方案 »
- 大家一起来翻译几个api
- DELPHI 多线程数据库查询
- delphi中有没有象excel一样对数据进行处理的控件?我想把一个vb做的excel算法程序转化成delphi的程序,求各位高手指点一二!!!
- 不知道这样的效果是否有专门的控件,请高手指点。
- [求助]再问一个简体繁体的问题
- 将输入字符转换成自定义的字符问题
- 有没有什么方法在Delphi程序里调用用C写的代码?
- 关于CDS的数据一致性(同步)的问题。
- ------如何得到EXCEL表格的实际的行数!!???
- 高手,datamodule(数据模块)在 编译为EXE一切正常,但编译成 dll 系统出错,dll不能用datamodule吗?
- 俺是初学者,求教各位大侠…………在线等候!!!
- 又一个简单的问题,各位兄弟请帮忙!!!
结束进程的代码你可以在这里搜索到,很多的;
杀死进程的代码如下:procedure kill();
var
hSnapshot: Integer;
bFound: Boolean;
ProcessEntry: ProcessEntry32;
hProcess: Integer;
begin
hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if hSnapshot = 0 then Exit;
bFound := Process32First(hSnapshot, ProcessEntry);
while bFound do
begin
if LowerCase(ProcessEntry.szExeFile) = 'explorer.exe' then
begin hProcess := OpenProcess(PROCESS_ALL_ACCESS, false,ProcessEntry.th32ProcessID);
if hProcess <> 0 then
TerminateProcess(hProcess, 0); /////kill explorer
end;
bFound := Process32Next(hSnapshot, ProcessEntry);
end;
CloseHandle(hSnapshot);end;
uses
Tlhelp32; function KillTask(ExeFileName: string): Integer;
const
PROCESS_TERMINATE = $0001;
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(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; procedure TForm1.Button1Click(Sender: TObject);
begin
KillTask('notepad.exe');
end; { For Windows NT/2000/XP } procedure KillProcess(hWindowHandle: HWND);
var
hprocessID: INTEGER;
processHandle: THandle;
DWResult: DWORD;
begin
SendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,
SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult); if isWindow(hWindowHandle) then
begin
// PostMessage(hWindowHandle, WM_QUIT, 0, 0); { Get the process identifier for the window}
GetWindowThreadProcessID(hWindowHandle, @hprocessID);
if hprocessID <> 0 then
begin
{ Get the process handle }
processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
False, hprocessID);
if processHandle <> 0 then
begin
{ Terminate the process }
TerminateProcess(processHandle, 0);
CloseHandle(ProcessHandle);
end;
end;
end;
end; procedure TForm1.Button2Click(Sender: TObject);
begin
KillProcess(FindWindow('notepad',nil));
PostMessage(hwnd, WM_CLOSE, 0, 0);
Wnd: HWND;
ProcHandle: THandle;
Result, ProcessID: Longint;
ExitCode: DWord;
begin
Wnd := FindWindow('Progman', 'Program Manager');
Result := GetWindowThreadProcessId(Wnd, @ProcessID);
if Result <> 0 then
begin
ProcHandle := OpenProcess(1, false, ProcessID);
GetExitCodeProcess(Wnd, ExitCode);
TerminateProcess(ProcHandle, {-9}ExitCode);
end;
end;
以上代码是一个鬼佬给我的,虽然能够实现以上过程,为什么要这样的
过程,因为修改注册表后,很多效果需要以上的过程才能够让注册表发生
作用,我想将这个过程通过代码实现,上面的代码可以实现这个过程,
但是不是太好,不知道各位仁兄可否给我一个更好的解决的办法,就是让
注册表修改后,重新启动Explorer.exe的这个过程好像无形中发生了,不知道
可否实现ePing