I'm trying to run odbcad32.exe (Windows 10, 64 bit) from a program written in the Lazarus IDE. I tried building in 32 & 64 bit and always got an exception with this text:
Failed to execute : 740
Apparently, after some googling, it means that my program needs admin privileges, but I AM running it from an admin account. I can run odbcad32 from an icon on the desktop, from the console, and from a much older program written in Delphi IDE normally (no Windows questions about privileges), but not from a Lazarus code.
So what am I doing wrong? The program has to be crossplatform. I'll run something else in Unix/OSX.
Here is the source code ('smesse' is a procedure to show error messages):
uses SysUtils, Process;
...
function RunExe1(exefilename:string;var em:string):boolean;
var
exe:TProcess;
f:integer;
begin
exe:=TProcess.Create(nil);
exe.InheritHandles:=false;
exe.Executable:=exefilename;
for f:=1 to GetEnvironmentVariableCount do
exe.Environment.Add(GetEnvironmentString(f));
exe.Options:=exe.Options-[poWaitOnExit];
try
exe.Execute; // <--- Exception is raised here
result:=true;
em:='';
except
on e:exception do
begin
result:=false;
em:=e.Message;
end
end;
exe.Free;
end;
procedure Tselectdbw.odbcmanClick(Sender: TObject);
var
em:string;
begin
//if not RunExe1('C:\Windows\syswow64\odbcad32.exe',em) then smesse(em);
//if not RunExe1('C:\Windows\system32\odbcad32.exe',em) then smesse(em);
if not RunExe1('odbcad32.exe',em) then smesse(em);
end;
I ran it with a full path too. BTW, in Delphi I used WinAPI and it works fine even today:
procedure ShellOpenFile(hWnd:HWND;filename:string);
begin
shellexecute(hWnd,'open',
pansichar(filename),nil,nil,SW_SHOW)
end;