. Advertisement .
..3..
. Advertisement .
..4..
I am new to programs and searching the “createprocess error=193, %1 is not a valid win32 application” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. Here is the command line I use:
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,
nil,
FALSE, // TRUE makes no difference
0, // e.g. CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS makes no difference
nil,
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;
The error I’m getting is below:
193 (%1 is not a valid Win32 app)
Please give me the solution to this issue.
The cause:
You have got this error because of two reasons:
Solution:
To solve this problem, you must supply an executable file to
CreateProcess
. You requireShellExecute
instead ofCreateProcess
in the case you want to be able to open any file with its related applications.Let’s use Dependency Walker’s profile mode to determine precisely what is incorrect happening for investigating purpose and get more information.
Your
Button2Click
,Button3Click
functions passklad.xls
&smimime.txt
. These files are most likely not executables.ShellExecute
is used to open any file using the associated application.