Does any one else have this happen to their applications when using ShellExecute? : my program will work fine but, It will be never show (always minimised).
Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ShellApi, Tlhelp32;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure Delay(sec: longint);
procedure FormShow(Sender: TObject);
function KillTask(ExeFileName: string): Integer;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Delay(sec: longint);
var
tc: longint;
begin
tc :=GetTickCount;
repeat
Application.ProcessMessages;
until ((GetTickCount-tc) >= sec);
end;
function TForm1.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.FormShow(Sender: TObject);
begin
KillTask('PHONE.exe');
Label1.Caption := 'REBOOT MONEYPHONE IN 5 SECONDS';
Delay(1000);
Label1.Caption := 'REBOOT PHONE IN 4 SECONDS';
Delay(1000);
Label1.Caption := 'REBOOT PHONE IN 3 SECONDS';
Delay(1000);
Label1.Caption := 'REBOOT PHONE IN 2 SECONDS';
Delay(1000);
Label1.Caption := 'REBOOT PHONE IN 1 SECOND';
Delay(1000);
ShellExecute(Handle, 'open', 'C:\Documents and Settings\Administrator\Desktop\PHONE\PHONE.exe', nil, nil, SW_SHOWNORMAL) ;
application.terminate;
end;
end.