Run with elevated rights fails on WIN7
I am developing using Delphi 6 on a WinXP system.
I have been using the following function to run a program with elevated
rights.
function LB_RunAsAdminWait(hWnd: HWND;
filename: string;
Parameters: string): Boolean;
var sei: TShellExecuteInfo; // shell execute info
begin
Result := False; // default to failure
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_FLAG_NO_UI or SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb := 'runas';
sei.lpFile := PChar(filename);
sei.lpParameters := PChar(Parameters);
sei.nShow := SW_SHOWNORMAL;
if ShellExecuteEx(@sei) then // if success
Result := True; // return sucess
if sei.hProcess <> 0 then begin // wait for process to finish
while WaitForSingleObject(sei.hProcess, 50) = WAIT_TIMEOUT do
Application.ProcessMessages;
CloseHandle(sei.hProcess);
end;
end; // of function LB_RunAsAdminWait
How I call it:
if (LB_RunAsAdminWait(FPGM.Handle,'RegSvr32',FName+' /s') = False) then
begin
ShowMessage('WARNING: unable to register OCX');
exit;
end;
where FPGM.handle is the handle to my application and Fname is the OCX i
want to register.
When I run it on a WIN7 machine it returns true(successful) but the OCX is
not registered.
Any help would be appreciated.
No comments:
Post a Comment