Jump to content

How to programmatically elevate a process as needed


Recommended Posts

Is there a way to programmatically elevate a process as needed? I am looking for functionality like how Windows Task Manager has the UAC shield on the button and gives a UAC prompt after clicking on the "Show processes from all users" button.

#RequireAdmin elevates the process right when the script is initialized, but sometimes programs don't always need elevation (such as Task Manager without looking at all users processes) and that brings unnecessary UAC prompts.

Basically, I have a process monitoring script, but one of the things it monitors is process specific network usage using "netstat -b". This is the only thing that requires elevation in the script, but in general people won't always need to have this turned on an the UAC prompt is annoying.

I'd like some kind of functionality so I can elevate the process in the middle of running as needed.

I'd guessing it'd be optimal if it could be implemented in the following way:

If Not IsAdmin() Then
    MsgBox(0, "This program requires elevation.", "Click OK to elevate the script.")
    RequestElevation()  ;<-- This is the function I'd like!
EndIf

A workaround to doing this may be something like have two scripts with the first without the #RequireAdmin keyword and the second being called from the first with the #RequireAdmin keyword, but that leads to other issues (I have updating code that would need to support this, etc).

Link to comment
Share on other sites

Probably not because you want to change the elevation midway through the program?

I actually do want to elevate midway through the program.

If the user enables network tracking (uses "netstat -b" which requires elevation), and clicks "Apply", then it will elevate the process at that point if not IsAdmin().

Is this possible?

Link to comment
Share on other sites

This is not possible with AutoIt. In Delphi, you need a Com-Object do to this... http://developersoven.blogspot.com/2007/02...-part_3659.html

But you can add the UAC in the manifest, so you're only questionec on Vista, not on XP -> http://community.bartdesmet.net/blogs/bart...ing-mt.exe.aspx

Microsoft supposes to split your app in 2 exe or exe + service :mellow:Splitting an Application into Standard User and Administrator Components

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...