有个程序,我直接双击可以正常运行,通过我的程序调用createprocess启动就出错
我发现那个程序如果双击直接运行的话,是通过createprocessW启动的。
所以我想在我的程序中也通过createprocessW方法来启动那个程序,但怎么执行都失败,也没什么错误。代码如下:var ProcessInformation: TProcessInformation;
CreateProcResult: Boolean;
StartUpInfoW: TStartUpInfoW;
begin
ZeroMemory(@StartUpInfoW, 0);
FillChar(StartUpInfoW, sizeof(StartUpInfoW), 00);
with StartUpInfoW do
begin
cb := sizeof(StartUpInfoW);
dwFlags := STARTF_USESHOWWINDOW; //StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle := nil;
wShowWindow := SW_SHOW;
end;
try
CreateProcResult := CreateProcessW(nil, PWideChar(AppPath), nil, nil, true,
0, nil, nil, StartUpInfoW, ProcessInformation);
except
on E:Exception do
ShowMessage(E.Message);
end;
if CreateProcResult then
showmessage('执行成功')
else
showmessage('执行失败');
end;不懂的,不会的,来学习的,就别顶了,我会自己关注帖子,谢谢合作。
我发现那个程序如果双击直接运行的话,是通过createprocessW启动的。
所以我想在我的程序中也通过createprocessW方法来启动那个程序,但怎么执行都失败,也没什么错误。代码如下:var ProcessInformation: TProcessInformation;
CreateProcResult: Boolean;
StartUpInfoW: TStartUpInfoW;
begin
ZeroMemory(@StartUpInfoW, 0);
FillChar(StartUpInfoW, sizeof(StartUpInfoW), 00);
with StartUpInfoW do
begin
cb := sizeof(StartUpInfoW);
dwFlags := STARTF_USESHOWWINDOW; //StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle := nil;
wShowWindow := SW_SHOW;
end;
try
CreateProcResult := CreateProcessW(nil, PWideChar(AppPath), nil, nil, true,
0, nil, nil, StartUpInfoW, ProcessInformation);
except
on E:Exception do
ShowMessage(E.Message);
end;
if CreateProcResult then
showmessage('执行成功')
else
showmessage('执行失败');
end;不懂的,不会的,来学习的,就别顶了,我会自己关注帖子,谢谢合作。
下在的代码可用:var
AppPath: WideString = 'F:\新建文件夹\TOOLS\COMDEBUG2.0.exe';procedure AddPro;
var
CreateProcResult: Boolean;
StartUpInfoW: TStartUpInfo;
ProcessInformation: TProcessInformation;
begin
ZeroMemory(@StartUpInfoW, 0);
FillChar(StartUpInfoW, sizeof(StartUpInfoW), 00);
with StartUpInfoW do
begin
cb := sizeof(StartUpInfoW);
dwFlags := STARTF_USESHOWWINDOW; //StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle := nil;
wShowWindow := SW_SHOW;
end;
try
CreateProcResult := CreateProcessW(nil, PWideChar(AppPath), nil, nil, true,
0, nil, nil, StartUpInfoW, ProcessInformation);
except
on E:Exception do
ShowMessage(E.Message);
end;
if CreateProcResult then
showmessage('执行成功')
else
showmessage('执行失败');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AddPro;
end;
但我的程序启动那个程序还是出错。
直接桌面双击快捷方式运行就没有错,用我的程序启动就出错。
是我调用createprocessW的参数不对吗?
运行别的程序也不出错,就这个程序出错。
能给些建议吗?
谢谢。
CreateProcResult := CreateProcess(nil, PChar(AppPath), nil, nil, true,
0, nil, PChar(appPath), StartUpInfo, ProcessInformation);如果这里PChar(appPath)换成nil的话,那个程序直接出错。
我在调用createProcess之前定义的appPath是wideString类型,没做处理。定义成String就好了。谢谢各位。