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
Message>You are not running as Admin%crlf%Goodbye...
CloseWindow>Macro Scheduler Message
MDL>The program was started elevated and is running as planned.