Delphi代码
创建带参数的进程的代码
var
si:STARTUPINFO;
pi:PROCESS_INFORMATION;
tp:string;
exepathname:string;
param1:string;
...
ZeroMemory(@si,sizeof(STARTUPINFO));
si.cb:=sizeof(STARTUPINFO);
si.lpReserved:=nil;
si.lpDesktop:=nil;
si.lpTitle:=nil;
si.cbReserved2:=0;
si.lpReserved2:=nil;
si.dwFlags:=STARTF_USESHOWWINDOW;
si.wShowWindow:=SW_SHOW;
if not
CreateProcess(pchar(exepathname), pchar(param1),
nil,nil,false,NORMAL_PRIORITY_CLASS,
nil,nil,si,pi) then
//失败
//tp:=exepathname+ ' ' + param1;
//if not
CreateProcess(nil, pchar(tp),
nil,nil,false,NORMAL_PRIORITY_CLASS,
nil,nil,si,pi) then
//成功
进程获取参数的代码
//paramstr[0]是你的可执行文件的路径,从1开始是你的程序的参数
icount:=paramcount();
if ( icount>= 0) then
begin
for i := 1 to icount do
begin
param[i]:= paramstr(i);
end;
end;
//c++获取进程参数
LPTSTR lpCmdLine=GetCommandLine();
char seps[]=" ";
char *token=NULL;
token=strtok(lpCmdLine,seps);
if (token!=NULL)
{
token=strtok(NULL,seps);
if (token!=NULL)
strcpy(param1,token);
else
return false;
}
else
return false;