在Windows 2K下,使用任务管理器结束进程Explorer.exe,然后点击新任务
按钮,重新运行Explorer.exe,这个过程用代码的方式如何实现?望不吝赐教,多谢!!
ePing

解决方案 »

  1.   

    新任务我想你可以用WINEXEC来打开;
    结束进程的代码你可以在这里搜索到,很多的;
      

  2.   

    在uses中家入tlhelp32
    杀死进程的代码如下: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;
      

  3.   

    结束进程的代码确实很多,代你贴一段:
    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)); 
      

  4.   

    可不可以向他发送关闭的消息如:
    PostMessage(hwnd, WM_CLOSE, 0, 0);
      

  5.   

    var
      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