Saturday, October 10, 2009

How to simplify CreateProcess

Simplification of CreateProcess function
procedure dgCreateProcess(const FileName: string);
var ProcInfo: TProcessInformation;
    StartInfo: TStartupInfo;
begin
     FillMemory(@StartInfo, sizeof(StartInfo), 0);
     StartInfo.cb := sizeof(StartInfo);
     CreateProcess(
                   nil,
                   PChar(FileName),
                   nil, Nil, False,
                   NORMAL_PRIORITY_CLASS,
                   nil, nil,
                   StartInfo,
                   ProcInfo);
     CloseHandle(ProcInfo.hProcess);
     CloseHandle(ProcInfo.hThread);
end;
Example of usage
CreateProcess('C:\Windows\Notepad.exe');
CreateProcess('notepad');
CreateProcess('mspaint');

No comments:

Post a Comment

Blogroll(General programming and Delphi feeds)