如何执行一个外部程序?有点难度,请高手们进(100分)

  • 主题发起人 主题发起人 dwxm
  • 开始时间 开始时间
测试程序已发,请试试。
 
在我的机器上,下面代码提示无法打开游戏配置文件,<br>Error:cannot open game setting file[game.ini]<br><br>procedure TForm3.Button1Click(Sender: TObject);<br>begin<br>WinExec('D:/TEST/TEST.EXE', SW_SHOW);<br>end;
 
学习一下
 
在Delphi中直接运行,显示“检查到非常程序”,如果直接运行编译后的程序,则正常,我用的是winexec<br>程序加壳了,ASProtect 2.1x SKE -&gt; Alexey Solodovnikov,外壳检测是否有调试程序
 
function WinExecAndWait32(FileName: string; Visibility: Boolean): integer;stdcall;<br>var<br> &nbsp;zAppName: array[0..512] of char; //存放应用程序名<br> &nbsp;StartupInfo: TStartupInfo;<br> &nbsp;ProcessInfo: TProcessInformation;<br> &nbsp;exitCode: Dword;<br> &nbsp;aVisibility: integer;<br>begin<br> &nbsp;try<br> &nbsp;StrPCopy(zAppName, FileName);<br> &nbsp;FillChar(StartupInfo, Sizeof(StartupInfo), #0);<br> &nbsp;//给StartupInfo结构体赋值<br> &nbsp;StartupInfo.cb := Sizeof(StartupInfo);<br> &nbsp;StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br> &nbsp;if Visibility then<br> &nbsp; &nbsp;aVisibility := 1<br> &nbsp;else<br> &nbsp; &nbsp;aVisibility := 0;<br><br> &nbsp;StartupInfo.wShowWindow := aVisibility;<br> &nbsp;//调用CreateProcess 创建进程,执行指定的可执行文件<br> &nbsp;if not CreateProcess(nil, zAppName, nil, nil, false<br> &nbsp; &nbsp;, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS<br> &nbsp; &nbsp;, nil, nil, StartupInfo, ProcessInfo) then<br> &nbsp; &nbsp;Result := -1<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;//等待可执行文件退出<br> &nbsp; &nbsp;WaitforSingleObject(ProcessInfo.hProcess, INFINITE);<br> &nbsp; &nbsp;//得到进程终止状态码<br> &nbsp; &nbsp;GetExitCodeProcess(ProcessInfo.hProcess, exitCode);<br> &nbsp; &nbsp;result := Exitcode;<br> &nbsp;end;<br>end;<br><br>WinExecAndWait32(filename,True);//filename &nbsp;文件路径名+.exe名
 
感谢 一诺 释疑,是加壳的问题,谢谢,已解决
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部