Possible Duplicates:
Delphi: Prompt for UAC elevation when needed
Delphi Administrator rights D7 W7
I'm using Delphi 7 on Windows 7. I need administrator privileges for some function in my application, which needs RAW access to the physical drive. How do I elevate to Administrator from source code? I.E. I chceck rights with:
function IsUserAdmin : boolean;
const CAdminSia : TSidIdentifierAuthority = (value: (0, 0, 0, 0, 0, 5));
var sid : PSid;
ctm : function (token: dword; sid: pointer; var isMember: bool) : bool; stdcall;
b1 : bool;
begin
result := false;
ctm := GetProcAddress(LoadLibrary('advapi32.dll'), 'CheckTokenMembership');
if (@ctm <> nil) and AllocateAndInitializeSid(CAdminSia, 2, $20, $220, 0, 0, 0, 0, 0, 0, sid) then
begin
result := ctm(0, sid, b1) and b1;
FreeSid(sid);
end;
end;
If the application is started as administrator, then return True if not then False. Now if I have False as the result, I want to automatically elevate to Administrator.
I tried manifest elevation to administrator, but if I start the application, then I see the UAC prompt. If i answer NO, then application will not run at all.
EDIT: Or disable UAC only for this application (ParamStr(0)) also from code (after pressing "Disable UAC for this application" button