Jump to content

How to force my AutoIt script to require administrator privileges?

Recommended Posts

I've googled and forum-searched a bit for this, and I can't seem to find exactly the right answer. Can anyone help?

My AutoIt script does, among other things, some launching of some third-party programs that perform specialized tasks that I can't do from within AutoIt. Those programs require administrator privileges in order to get their work done. If those programs don't have administrator privileges when I shell out to them, then they will silently fail to accomplish their tasks. I want my AutoIt script (well, actually the EXE that I'm eventually going to compile and distribute from it) to require administrator privileges of its own before it will allow the user to continue.

Please don't reply with instructions on how to make a shortcut to my AutoIt program, and then tick the "Administrator" tickybox in the shortcut, or describe how I can right-click on my AutoIt program and say "Run as administrator". I know how to do those things! In fact, that's how I could check to be sure that setting the AutoIt script to Admin privileges would work for my purposes. No, when I googled and forum-searched for this, that was what all the search results said: "Make a shortcut"... or "use the command-line RunAs..." etc... That's not what I'm asking here.

I'm asking, how, within the AutoIt script code itself, how can I force it so that when a user runs my AutoIt program without admin privileges, that it will force the OS to put up the UAC box and ask the user if it's OK to allow my program to make changes to the system?

Alternatively, if that can't be done, how can I, within AutoIt, check to see whether my program is currently running under administrator privileges, thus allowing me to put up my own error box and terminate my program?

There was one search result that looked promising. The result talked about adding this line to my code:


But when I put that line at the top of my code, there doesn't appear to be any change in the way the program runs. What is that line from, how is it supposed to work, and what am I doing wrong about implementing it?

Are there any other ways to accomplish what I want?

Link to post
Share on other sites

Try #RequireAdmin, and to check if the current user is an admin, try IsAdmin(), see the help file for anything that doesn't make sense.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to post
Share on other sites

Try #RequireAdmin, and to check if the current user is an admin, try IsAdmin(), see the help file for anything that doesn't make sense.

Excellent! Exactly what I was looking for! Thank you so much!

So simple, I can't believe I didn't find it in my initial search. Feel kind of bad for bothering the forum with something so simple. ;)

Link to post
Share on other sites

The AutoIt3Wrapper is part of SciTE4AutoIt3, it is not included in the "lite" SciTE that you get in the AutoIt download. You should definitely install it if you're writing AutoIt code. Lots of other goodies to, check the site or just try it ;)

Edited by AdmiralAlkex
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...