title: Delphi Administrator rights D7 W7
body: <blockquote>
    <p><strong>Possible Duplicates:</strong><br>
    <a href="https://stackoverflow.com/questions/923350/delphi-prompt-for-uac-elevation-when-needed">Delphi: Prompt for UAC elevation when needed</a><br>
    <a href="https://stackoverflow.com/questions/6977893/delphi-administrator-rights-d7-w7">Delphi Administrator rights D7 W7</a>  </p>
  </blockquote>
  
  
  
  <p>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:</p>
  
  <pre><code>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 &lt;&gt; 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;
  </code></pre>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>EDIT: Or disable UAC only for this application (ParamStr(0)) also from code (after pressing "Disable UAC for this application" button</p>