Is Process Running Elevated?

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3467
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Is Process Running Elevated?

Post by JRL » Thu Nov 03, 2022 9:07 pm

For 30 years I was either the lone IT guy or the lead IT guy. In either case User Account Control or logging in to my desktop as Administrator or other administrative decisions were mine. Those days are gone. Probably a good thing. I may have been careless. But I did get away with it for 30 years.

Today I'm further down the IT ladder and part of an IT team. I do have full administrative access via a domain user account with administrative privileges but that account has to be used conditionally. I can no longer run my computer and all the programs on it as administrator. I find myself writing programs that require elevation to function properly. Unfortunately, I also find myself running those programs without elevation then watching them crash and burn. Old habits die hard.

Today I went looking for and discovered a microsoft library function to identify whether I've run a program elevated. The function is appropriately named "IsUserAnAdmin". Easy to use. Just place the following code at the top of your script then recompile. When you run the program correctly it just runs. If you forget to right click and "Run as administrator" the program will let you know then close gracefully.

Code: Select all

LibFunc>shell32,IsUserAnAdmin,AdminTest

If>AdminTest=1
Else
  Message>You are not running as Admin%crlf%Goodbye...
  Wait>2
  CloseWindow>Macro Scheduler Message
  Exit>0
EndIf

MDL>The program was started elevated and is running as planned.


User avatar
Grovkillen
Automation Wizard
Posts: 811
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Is Process Running Elevated?

Post by Grovkillen » Fri Nov 04, 2022 8:39 am

Simple and easy to implement. Thank you!
Let>ME=%Script%

Running: 15.0.20
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts