Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 951093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:40:30+00:00 2026-05-15T23:40:30+00:00

Windows 7, Vista, Server 2008, UAC is activated Program must be stated with admin

  • 0

Windows 7, Vista, Server 2008, UAC is activated

Program must be stated with admin rights to make some installation actions. After that I want my program to continue work with non-admin rights.

How can I restart it with not administrative rights?


P.S.

My program reinstall itself. I don’t want distribute any additional programs for it. So my steps are:

  1. Download new version in temp dir
  2. Restart itself under admin rights
  3. Rename old exe-file and copy new exe-file from temp dir
  4. Restart itself under non-admin rights
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:40:32+00:00Added an answer on May 15, 2026 at 11:40 pm

    Thanx to Kate Gregory for help.

    There is a working code on Delphi:

    function RunAsUser(CommandLine, WorkDirectory: string; Wait: Boolean): Boolean;
    const
      TOKEN_ADJUST_SESSIONID = $0100;
      dwTokenRights = TOKEN_QUERY or TOKEN_ASSIGN_PRIMARY or TOKEN_DUPLICATE or TOKEN_ADJUST_DEFAULT or TOKEN_ADJUST_SESSIONID;
    var
      WExe, WCmdLine, wCurrDir: WideString;
      hProcessToken, dwLastErr, retLength, hwnd, dwPID, hShellProcess, hShellProcessToken, hPrimaryToken: Cardinal;
      tkp: TOKEN_PRIVILEGES;
      PI: TProcessInformation;
      SI: TStartupInfoW;
    begin
      Result:= False;
    
      hShellProcessToken:= 0;
      hPrimaryToken:= 0;
      hShellProcess:= 0;
    
      if WorkDirectory = '' then WorkDirectory:= GetCurrentDir;
      Wexe:= SeparateText(CommandLine, ' ');
      WCmdLine:= CommandLine;
      wCurrDir:= WorkDirectory;
    
        // Enable SeIncreaseQuotaPrivilege in this process.  (This won't work if current process is not elevated.)
        if not OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, hProcessToken) then Exit;
    
      tkp.PrivilegeCount:= 1;
      LookupPrivilegeValueW(nil, SE_INCREASE_QUOTA_NAME, tkp.Privileges[0].Luid);
      tkp.Privileges[0].Attributes:= SE_PRIVILEGE_ENABLED;
      AdjustTokenPrivileges(hProcessToken, FALSE, tkp, 0, nil, retLength);
      dwLastErr:= GetLastError();
      CloseHandle(hProcessToken);
      if (dwLastErr <> ERROR_SUCCESS) then Exit;
    
        // Get an HWND representing the desktop shell.
        // CAVEATS:  This will fail if the shell is not running (crashed or terminated), or the default shell has been
        // replaced with a custom shell.  This also won't return what you probably want if Explorer has been terminated and
        // restarted elevated.
    
        hwnd:= GetShellWindow();
      if hwnd = 0 then Exit;
    
      // Get the PID of the desktop shell process.
      GetWindowThreadProcessId(hwnd, dwPID);
      if dwPID = 0 then Exit;
    
      // Open the desktop shell process in order to query it (get the token)
      hShellProcess:= OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwPID);
      if hShellProcess = 0 then Exit;
    
      // From this point down, we have handles to close, so make sure to clean up.
      try
        // Get the process token of the desktop shell.
        if not OpenProcessToken(hShellProcess, TOKEN_DUPLICATE, hShellProcessToken) then Exit;
    
        // Duplicate the shell's process token to get a primary token.
        // Based on experimentation, this is the minimal set of rights required for CreateProcessWithTokenW (contrary to current documentation).
        if not DuplicateTokenEx(hShellProcessToken, dwTokenRights, nil, SecurityImpersonation, TokenPrimary, hPrimaryToken) then Exit;
    
        SI.cb:= SizeOf(SI);
        FillChar(SI, SI.cb, 0);
        SI.wShowWindow:= SW_SHOWNORMAL;
        SI.dwFlags:= STARTF_USESHOWWINDOW;
    
        // Start the target process with the new token.
        Result:= CreateProcessWithTokenW(
          hPrimaryToken,
          0,
          PWideChar(WExe),
          PWideChar(wCmdLine),
          0,
          nil,
          PWideChar(wCurrDir),
          @si,
          @pi);
    
        if not Result then Exit;
    
        if Wait then
          while MsgWaitForMultipleObjects(1, PI.hProcess, False, INFINITE, QS_ALLINPUT) <> WAIT_OBJECT_0 do
            ProcessMessages;
    
        CloseHandle(PI.hProcess);
      finally
        // Clean up resources
        CloseHandle(hShellProcessToken);
          CloseHandle(hPrimaryToken);
        CloseHandle(hShellProcess);
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 460k
  • Answers 460k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Something like this helps you to extract the content :… May 15, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer the issue is solved by setting the following fields <Start>2010-07-19T08:00:00</Start>… May 15, 2026 at 11:41 pm
  • Editorial Team
    Editorial Team added an answer I think there is nothing to do about this. Maybe… May 15, 2026 at 11:41 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.