Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Pascal Delphi Misc > How to kill exp...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 5995 of 6153
Post > Topic >>

How to kill explorer.exe?

by Ikke <ikke@[EMAIL PROTECTED] > Feb 24, 2008 at 04:07 PM

Hi everybody,

For a kiosk application, I'm trying to start an application through code, 
and later on kill the same application. With a standard application, it 
works like a charm.

But when I try to do the same with explorer.exe, I can't kill the 
process. The reason is most likely the fact that there is always only one 
explorer.exe process, albeit with multiple windows.

Here is my code:
// create the process
procedure TForm1.CreateClick(Sender: TObject);
var
  sProgram: String;
  zCommand: array[0..512] of char;
  si: TStartupInfo;
  dwError: DWORD;
begin
  sProgram := 'c:\winnt\notepad.exe';

  if (Pos(' ', sProgram) > 0) and (sProgram[1] <> '"') then
    sProgram := AnsiQuotedStr(sProgram, '"');

  StrPCopy(zCommand, sProgram);
  FillChar(si, SizeOf(si), #0);
  si.cb := SizeOf(si);
  si.dwFlags := STARTF_USESHOWWINDOW;
  si.wShowWindow := SW_SHOWNORMAL;
  if CreateProcess(nil, zCommand, nil, nil, False,
                   CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,
                   nil, nil, si, FProcessInfo) then
  begin
  end
  else
  begin
    ShowMessage('Createprocess failed!');
  end;
end;

// kill process
procedure TForm1.KillClick(Sender: TObject);
var
  uExitCode: Cardinal;
  sAuto: String;
begin
  uExitCode := 0;

  if TerminateProcess(FProcessInfo.hProcess, uExitCode) then
  begin
    ShowMessage('Terminated');
  end
  else
  begin
    ShowMessage('Termination failed!');
    ShowMessage('Exit code: ' + IntToStr(uExitCode));
  end;
end;
// end code snippet

Does anybody know a way to kill one particular explorer.exe window? 

Thanks in advance!

Ikke
 




 1 Posts in Topic:
How to kill explorer.exe?
Ikke <ikke@[EMAIL PROT  2008-02-24 16:07:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 7 16:10:39 CDT 2008.