Windows

Elevate privileges automatically with Elevation PowerToys

Greg Shultz introduces you to the Elevation PowerToys for Microsoft Windows Vista and shows you how to use them to more easily launch scripts that require elevated privileges.

I recently received an e-mail from a reader who asked me if there was a better way to elevate privileges when running scripts in Microsoft Windows Vista. He went on to explain that the only existing procedure for doing so was kludgy and removed the convenience factor inherent in using a script to automate a task. Instead of simply double-clicking on the script to run it, he had to first open a Command Prompt with elevated privileges, which meant right-clicking the Command Prompt, selecting Run as Administrator, responding to the UAC, and then finally typing the command to launch the script.

That's when I realized that I hadn't written about the Elevation PowerToys for Windows Vista, which were specifically designed to address this problem.

In this edition of the Windows 7 and Windows Vista Report, I'll introduce you to Elevation PowerToys for Windows Vista and show you how to use them to more easily launch scripts that require elevated privileges.

This blog post is also available in PDF format in a free TechRepublic download.

Not all scripts need elevated privileges

Before I begin telling you about the Elevation PowerToys, I need to point out that not all scripts need to run with elevated privileges -- only those that are designed to perform tasks that cross over the boundary into Vista's User Account Control (UAC) territory. As you may know, any application, or script for that matter, that will change the way the operating system works or will affect other user accounts on the system requires elevated privileges in order to run. To get these elevated privileges, most applications automatically trigger a UAC, which either prompts the user to continue or to provide an Administrative password.

Of course, any application or script that does not change the operating system can run with standard privileges. For example, back in March 2008, I presented three HTML Application scripts that can run without elevated privileges, in the articles "Unlocking the Bubbles Screen Saver's Hidden Settings in Vista" and "Unlocking the Ribbons and Mystify Screen Savers' Hidden Settings in Vista." (As you may know, HTML Applications, or HTAs for short, are essentially scripts that use a combination of HTML, Windows Script Host, and VBScript or Jscript to perform a task.)

The PowerToys

Fortunately, Michael Murgolo, a Senior Infrastructure Consultant for Microsoft Consulting Services, recognized that not having a convenient way to launch scripts with elevated privileges in Vista was a problem. As such, he created the Script Elevation PowerToys for Windows Vista, which you can read about and download from Microsoft's TechNet site.

Once you download the Elevation2008_06.exe package, just double-click it and you'll see the TechNet Magazine Sample Code dialog box, shown in Figure A, which prompts you to select a folder where you want to expand all the files included in the Script Elevation PowerToys. This procedure will not install any of the tools.

Figure A

When you launch the file, it will prompt you to choose a location in which to expand all the files in the package.

Once you expand the package, you'll find a folder titled Elevation that contains a host of INF files that will allow you to pick and choose which Script Elevation PowerToys you want to install. You'll also find a CMD file named InstallAllPowerToys.cmd that will allow you to install all the Script Elevation PowerToys. Unless you know that you will be running all sorts of scripts, I would suggest that you install only those Script Elevation PowerToys for the types of scripts that you will be running. Be sure to investigate the Readme.txt file for more detailed information.

Installing a PowerToy

Installing any one of the Script Elevation PowerToys is a snap. For example, let's suppose that you know that you will be running HTA files that will require elevated privileges. You would locate and right-click on the ElevateHTA.inf file and select the Install command, as shown in Figure B.

Figure B

To install the Elevate HTML Application PowerToy, right-click on the ElevateHTA.inf file and select the Install command.
Once you install the Elevate HTML Application PowerToy, you will discover that there is now a Run as Administrator command on the context menu for HTA files, as shown in Figure C. Of course, when you select this command, you'll see a UAC and must select the appropriate response. When you do, your HTA will run, and it will be able to perform whatever task it was designed to accomplish.

Figure C

You can now easily run an HTA script that requires elevated privileges simply by selecting the Run as Administrator command.

Uninstalling a PowerToy

Uninstalling any one of the Script Elevation PowerToys is just as easy as installing one. However, you do it from within the Programs and Features tool, which you can access in Control Panel. For example, after installing the Elevate HTML Application PowerToy, you'll find an entry for it in the Programs and Features tool, as shown in Figure D.

Figure D

You can uninstall any of the Script Elevation PowerToys from the Programs and Features tool.

Keep in mind that if you choose to install all of the Script Elevation PowerToys, you will find a separate CMD file named UninstallAllPowerToys.cmd that will allow you to uninstall all the Script Elevation PowerToys at the same time.

What's your take?

Have you encountered a problem running a script in Vista? Are you already using the Script Elevation PowerToys? If so, what has been your experience using these PowerToys? As always, if you have comments or information to share about these topics, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.

TechRepublic's Windows Vista and Windows 7 Report newsletter, delivered every Friday, offers tips, news, and scuttlebutt on Vista and Windows 7, including a look at new features in the latest version of the Windows OS. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

18 comments
jhcwge
jhcwge

So is there a way then to automatically install a custom msi file onto a user machine with elevated privileges via group policy over the network..??? Also, can those PowerToys be pushed out to users via group policy if necessary to do so...??

Chug
Chug

I haven't downloaded and tried these yet, but from what I can tell by the single example given, it looks like these only help with elevating a script by running it manually. How would I elevate something automatically, like from a login script, or I have something I need to put in the HKLM\Software\Microsoft\Windows\CurrentVersion\Run registry setting to run every time the PC starts up that requires elevated rights.

PeterM42
PeterM42

Any ideas when Microsoft developers are going to produce a "cmdhere" PowerToy?

Mark W. Kaelin
Mark W. Kaelin

Have you encountered a problem running a script in Vista? Are you already using the Script Elevation PowerToys? If so, what has been your experience using these PowerToys?

Mark W. Kaelin
Mark W. Kaelin

Had a small technical problem - it should be downloadable now. If not send me a private message and I'll make sure you get it.

ljkraus
ljkraus

I tried downloading this package from TechNet, but I getting a message "We?re sorry! The page you were expecting to see has been removed or is unavailable." Is this tool truly unavailable or is this because I lack a TechNet subscription?

Lazarus439
Lazarus439

Thanks! ...stupid computers.... :)

Lazarus439
Lazarus439

I still can't download the PDF. The problem seems to be the links on the download page itself that are supposed to download the PDF. The link from the article to the download trigger page works fine - it opens the standard TechRepublic download trigger page as usual. When I click the Download button on the trigger page, which normally opens a new windows with the PDF in it and also goes the "Was This Useful" page, I do not get the PDF in the new window. I get the TechRepublic home page. Also, the link on the "Was This Useful" page that's supposed to be the backup if the PDF doesn't show up in the new window does the same thing. This latter link, (http://i.techrepublic.com.com/downloads/gshultz_V7R_elevation_powertoy.pdf) is apparently where the PDF is supposed to be, but even pasting this URL directly into browser window doesn't find the PDF. I've tried this on two different computers with two different OS and two different browsers using two different ISPs. It sure doesn't seem like the problem is at my end. Thanks!

Chug
Chug

Thanks! That does look like it should do the trick.

apete
apete

Nice to have it built-in.

PeterM42
PeterM42

Thanks guys - much appreciated. PeterM

Matte303
Matte303

Here's a registry change that will make it show up without pressing the Shift key. This change also makes it show up in the Left (folder tree) pane as well. http://www.watchingthenet.com/how-to-always-display-open-command-window-here-context-menu-in-windows-vista.html Also, you can make the same change to HKEY_CLASSES_ROOT\Directory\Background\shell\cmd which gets you the command on the folder pane background in Windows Explorer and here: HKEY_CLASSES_ROOT\Drive\shell\cmd which gets you the command on drive icons