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.)
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.
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 PowerToyInstalling 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.
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.
You can now easily run an HTA script that requires elevated privileges simply by selecting the Run as Administrator command.
Uninstalling a PowerToyUninstalling 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.
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!
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.