--> The trick to restart the explorer.exe process was active. | Delphi Tips Trick

For Newbie

Tuesday, 15 November 2011

The trick to restart the explorer.exe process was active.

| Tuesday, 15 November 2011

Declaration procedure:
RestartExplorer function: Boolean;
var
   wHnd: hWnd;
   PID: DWORD;
   hProc: THandle;
   Exc: DWORD;
begin
   wHnd: = FindWindow ('Progman', 'Program Manager');
   if wHnd <> 0 then
   begin
     GetWindowThreadProcessID (wHnd, PID);
     hProc: = OpenProcess (PROCESS_QUERY_INFORMATION or PROCESS_TERMINATE, False, PID);
     GetExitCodeProcess (hProc, exc);
     Result: = TerminateProcess (hProc, exc);
    {For some cases, the explorer will automatically execute
     himself, but if it fails:
     Add WinExec ('explorer', SW_SHOWNORMAL);}
     CloseHandle (hProc);
   end
   else Result: = False;
end;

Example of implementation:
procedure TForm1.Button1Click (Sender: TObject);
begin
   if RestartExplorer then ShowMessage ('OK') else ShowMessage ('FAIL');
end;

Related Posts

No comments: