以下代码无法启动文档.我得到错误193(%1不是有效的Win32应用程序).启动可执行文件工作正常.
文件正确关联,双击时启动相应的应用程序.
我搜索了SO和其他地方的错误消息,创建处理内容等(例如 Why is CreateProcess failing in Windows Server 2003 64-bit?
我知道引用命令行.
文件正确关联,双击时启动相应的应用程序.
我搜索了SO和其他地方的错误消息,创建处理内容等(例如 Why is CreateProcess failing in Windows Server 2003 64-bit?
我知道引用命令行.
>这是Win7 64位VMWare虚拟机中的一个Delphi XE2(Update 4)Win32应用程序.
>代码在主机(Win7 64位)和虚拟PC虚拟机(32位XP)中也失败.
>应该在Win7 VM(Excel 2003和Crimson Editor)中启动的应用程序是32位.
>从IDE启动或独立运行测试应用程序时,都会发生故障
>它以前是Delphi2007代码,编译的D2007应用程序,这个代码来自工作正常到处.
代码有什么问题?几乎好像我忽略了很明显的东西….
提前致谢,
一月
procedure StartProcess(WorkDir,Filename: string; Arguments : string = ''); var StartupInfo : TStartupInfo; ProcessInfo : TProcessInformation; lCmd : string; lOK : Boolean; LastErrorCode: Integer; begin FillChar( StartupInfo,SizeOf( TStartupInfo ),0 ); StartupInfo.cb := SizeOf( TStartupInfo ); StartupInfo.dwFlags := STARTF_USESHOWWINDOW; StartupInfo.wShowWindow := sw_Normal; FillChar( ProcessInfo,SizeOf( TProcessInformation ),0 ); lCmd := '"' + WorkDir + FileName + '"'; // Quotes are needed https://stackoverflow.com/questions/265650/paths-and-createprocess if Arguments <> '' then lCmd := lCmd + ' ' + Arguments; lOk := CreateProcess(nil,PChar(lCmd),nil,FALSE,// TRUE makes no difference 0,// e.g. CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS makes no difference nil,// PChar(WorkDir) makes no difference StartupInfo,ProcessInfo); if lOk then begin try WaitForSingleObject(ProcessInfo.hProcess,INFINITE); finally CloseHandle( ProcessInfo.hThread ); CloseHandle( ProcessInfo.hProcess ); end; end else begin LastErrorCode := GetLastError; ShowMessage(IntToStr(LastErrorCode) + ': ' + SysErrorMessage(LastErrorCode)); end; end; procedure TFrmStartProcess.Button1Click(Sender: TObject); begin StartProcess('c:\program files (x86)\axe3\','axe.exe'); // Works end; procedure TFrmStartProcess.Button2Click(Sender: TObject); begin StartProcess('d:\','klad.xls'); // Fails end; procedure TFrmStartProcess.Button3Click(Sender: TObject); begin StartProcess('d:\','smimime.txt'); // Fails end;