Jump to content
Sign in to follow this  
duckling78

How to programmatically elevate a process as needed

Recommended Posts

duckling78

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).

Share this post


Link to post
Share on other sites
Richard Robertson

Many questions like this have come up before. It's just not doable at a user level.

Share this post


Link to post
Share on other sites
Glyph

Try the runas() command?

Not sure if that's wha you mean.

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

Edited by Glyph

tolle indicium

Share this post


Link to post
Share on other sites
duckling78

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?

Share this post


Link to post
Share on other sites
ProgAndy

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.