dobra zrobilem to juz, wczesniej korzystalem z terminateprocess ale nie dzialalo, dopiero taki kodzik zadzialal:
var
aProcessInfo: PROCESS_INFORMATION;
aProcessSecAttr: SECURITY_ATTRIBUTES;
aThreadSecAttr: SECURITY_ATTRIBUTES;
aStartupInfo: STARTUPINFO;
hProcessHandle:HWND;
function RunApp(commandLine: String): integer;
var
n: Boolean;
begin
with aProcessSecAttr do
begin
bInheritHandle := False;
lpSecurityDescriptor := nil;
nLength := sizeOf(aProcessSecAttr);
end;
with aThreadSecAttr do
begin
bInheritHandle := False;
lpSecurityDescriptor := nil;
nLength := sizeOf(aThreadSecAttr);
end;
with aStartupInfo do
begin
cb := sizeOf(aStartupInfo);
lpReserved := nil;
lpDesktop := nil;
lpTitle := nil;
dwX := 0;
dwY := 0;
dwXSize := 300;
dwYSize := 300;
dwXCountChars := 80;
dwYCountChars := 25;
dwFillAttribute := 0;
dwFlags := STARTF_USESTDHANDLES;
wShowWindow := SW_SHOWDEFAULT;
cbReserved2 := 0;
lpReserved2 := nil;
hStdInput := 0;
hStdError := 0;
hStdOutput := 0;
end;
n := CreateProcess(nil, @commandLine[1], nil, nil,
True, CREATE_NO_WINDOW + NORMAL_PRIORITY_CLASS,
nil, nil, aStartupInfo, aProcessInfo);
If n Then
RunApp := aProcessInfo.hProcess
Else
RunApp := -1;
end;
procedure CloseProcessHandles;
begin
terminateprocess(aProcessInfo.hThread,0);
terminateprocess(aProcessInfo.hProcess,0);
CloseHandle(aProcessInfo.hThread);
CloseHandle(aProcessInfo.hProcess);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
hProcessHandle := RunApp(extractfilepath(application.exename)+'notepad.exe');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
CloseProcessHandles;
end;
co do shellexecute, z tej funkcji wynika iz powinien zwraca handle'a:
function ExecuteFile(const FileName, Params, DefaultDir: string;
ShowCmd: Integer): THandle;
var
zFileName, zParams, zDir: array[0..79] of Char;
begin
Result := ShellExecute(Application.MainForm.Handle, nil,
StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
StrPCopy(zDir, DefaultDir), ShowCmd);
end;
(ale zaczynam miec watpy)
dzieki wszystkim za pomoc