Search code examples
lazarus

Shellexecute Error 2 - The specified file was not found


I'm trying:

cmdline := 'I:\test.exe';
Result := ShellExecute(0,nil, PChar(cmdline),PChar(''),nil,1)

Where I:\ is a network drive. This would give me the error: 2 - file not found

If I try:

cmdline := '\\10.10.10.10\data\test.exe';
Result := ShellExecute(0,nil, PChar(cmdline),PChar(''),nil,1)

Gives error: 5 - Access denied

So I guess ShellExecute does not get the mapped network drive, nor the credentials from the logged on user.

So how do I get ShellExecute to execute the command in the current user environment? Or more likely: What obvious thing am I missing?

Hoping @RBA gave me the obvious thing I have now tried:

FillChar( StartupInfo, SizeOf( TStartupInfo ), 0 );
StartupInfo.cb := SizeOf( TStartupInfo );
StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := sw_Normal;
FillChar( ProcessInfo, SizeOf( TProcessInformation ), 0 );

if CreateProcess(pchar(cmdline), Nil, Nil, Nil,
                 False, CREATE_NEW_CONSOLE, Nil, Nil, 
                 StartupInfo, ProcessInfo) then
  result := true
else
  result := false; 

But still no exe launched :( Same error: 2 - file not found. Makes me believe that there is something other than the code that is playing me a trick...


Solution

  • I finally found the obvious. The path given in the example above is just an example. The real path is:

    I:\Prosjekt\Læringssenteret\VgFriskoleIndivid\Program\utvOve\WisKrypt\Install
    

    And the problem is the norwegian character: æ But that does not explain why i got error 5 - access denied when trying UNC path...