
05-27-2007, 10:35 PM
|
 | Elite Members | | Join Date: Nov 2006 Location: S.W. Kansas
Posts: 2,841
| |
http://www.microsoft.com/technet/tec...aspx?year=2007
OK, seems he changed the link to: maybe I can find the original in my cache and c/p here...
here is my cache page: Quote:
Script Elevation PowerToys for Windows Vista
section: windows, for your questions: IT forum, 24.5.2007
Among the many features Windows Vista introduced to address security concerns, User Account Control (UAC) is one of the most significant. With User Account Control, even users who are administrators run most applications with standard privilege, but have "elevation potential" for specific administrative tasks and application functions.
After using Windows Vista™ for many months, elevating a task or application as necessary has become second nature. However, I also encountered a number of shortcomings when trying to elevate some types of tasks in Windows Vista, and that became frustrating.
So in the spirit of the old Windows® PowerToys, I’ve created a few Script Elevation PowerToys to overcome these limitations. You can find all of the PowerToys I’m about to discuss in the code download at technetmagazine .com/code07.aspx. And you can read about how UAC works in the November 2006 article "Achieve the Non-Admin Dream with User Account Control" by Alex Heaton (see the "Additional Resources" sidebar).
Elevate Command PowerToy
The first annoyance was that there was no method to elevate an application from the command line or from the Run dialog box. So after asking around within Microsoft, I came across a sample script from John Stephens (a Software Design Engineer at Microsoft) that provided the information I needed. It turns out that if you pass the verb "runas" to either the ShellExecute API or to its COM equivalent, the ShellExecute method of Shell.Application, the application launched will prompt for elevation (see the sidebar for details). This allowed me to create the first Elevation PowerToy—the Elevate Command PowerToy.
This tool (which consists of the files ElevateCommand.inf, elevate.cmd, and elevate.vbs) adds an elevate command to your system. This lets you launch applications that prompt for elevation from the command line, a script, or the Run dialog. For example, the following command opens Win.ini with Notepad (after prompting for elevation):
elevate notepad c:\Windows\Win.ini
When using the elevate command with Windows Script Host (WSH), Windows PowerShell™ or other scripts, you need to specify the script host executable (such as wscript, cscript, or powershell) as the application. To run a vbs, for example, you’d use this:
elevate wscript “C:\windows\system32\
slmgr.vbs” –dli
The help text explains this. Use elevate with -? or with no parameters to see the help text.
Run as Administrator for Scripts
The next irritant was that there was no "Run as Administrator" context menu option (when you right-click on the file in Explorer) for most Windows script types. The one exception was for command-shell scripts (those with .bat and .cmd file extensions). So I set out to investigate this. Many of the context menu options for file types are controlled through command keys for the "object" type in the HKEY_CLASSES_ROOT section of the Registry (see Verbs and File Associations in the sidebar for details). It turns out that if that command key is named runas, the command invoked will prompt for elevation. This allowed me to create the following PowerToys:
* Elevate HTML Application PowerToy (ElevateHTA.inf)
* Elevate Windows PowerShell Script PowerToy(ElevatePowerShellScript.inf)
* Elevate WSH Script PowerToy (ElevateWSHScript.inf, elevate.cmd, elevate.vbs)
source: microsoft.com/technet
| download the code here: http://download.microsoft.com/downlo...ity2007_06.exe
There are 12 Vista Toys all to gether.... 
__________________ The only Stupid Question is the one you failed to Ask! Beta Tester since Pre Win 95.
Last edited by Snuffy : 05-27-2007 at 10:43 PM.
|