The Elevation PowerToys and Windows 7
Important Update - 28 Jan 2009
A comment was posted to my December 22 post stating that the Elevate command in the Elevation PowerToys does not work correctly in the Windows 7 Beta. (Thanks Pete!) The application is launched elevated but the arguments are not passed to the application. It turns out that this is caused by a known bug in the Windows 7 Beta. The ShellExecute method of the Shell Scripting Objects does not pass the vArguments parameter when it is stored in a variable.
I had previously attached a VBScript that used the Execute statement to pass the ShellExecute parameters as literal strings as a workaround. While that worked for the particular case from the blog post, it broke others because I cannot predict the quoting that will be passed in to form a valid VBScript string.
However, as luck would have I found another workaround in the bug notes. If you append a blank string to the variable in the ShellExecute parameter list (i.e. passing an expression as the ShellExecute vArguments parameter) it works. I've attached an new updated version of Elevate.vbs that has the new workaround. Please give this a try if you are using the Elevation PowerToys with Windows 7. Simply replace the version in the Elevation PowerToys download with this one and reinstall the Elevate Command PowerToy using ElevateCommand.inf.
Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use .
This post was contributed by Michael Murgolo, a Senior Consultant with Microsoft Services - U.S. East Region.
Comments
Anonymous
January 01, 2003
So does the new version also work with Windows Vista?Anonymous
January 01, 2003
Pete, The bug is currently marked as "should be fixed" so I assume the goal is to fix it by RTM. Of course, this is always subject to change. Please note the new version of Elevate.vbs that I posted on 28 January. Please use that instead of the original one posted on 21 January. Michael MurgoloAnonymous
January 01, 2003
Michael, Will this be fixed in W7 RTM? PeteAnonymous
January 29, 2009
Michael, I found the quoting problem in my testing and was about to let you know; only to find you'd already found it to be a issue. I will test some more. PeteAnonymous
January 30, 2009
Just curious, will you guys post on MDT 2010 beta soon? -thanksAnonymous
May 02, 2009
Here is a piece of batch code for elevating a random batchfile I wrote based on this example. It first writes an elevate.vbs to %temp% then calls that file, that on it's turn calls the batchfile it was called from in elevated mode, passing the directory as an argument. The batchfile then changes directory to the arguments location and continues. rem - start of batchfile - if not "%1"=="" ( cd "%" goto :lbl_SkipElevate ) mkdir uactest 2>nul if errorlevel 1 ( set str_ElevName=%temp%elevate.vbs echo ' // Based on Elevation PowerToys for Windows Vista v1.1 (04/29/2008) > %str_ElevName% echo Set objShell = CreateObject("Shell.Application") >> %str_ElevName% echo Set objWshShell = WScript.CreateObject("WScript.Shell") >> %str_ElevName% echo Set objWshProcessEnv = objWshShell.Environment("PROCESS") >> %str_ElevName% echo strDir = objWshProcessEnv("ELEVATE_DIR") >> %str_ElevName% echo strApp = objWshProcessEnv("ELEVATE_APP") >> %str_ElevName% echo objShell.ShellExecute "" ^& strApp, "" ^& strDir, "", "runas" >> %str_ElevName% set ELEVATE_APP=%~nx0 set ELEVATE_DIR=%cd% start wscript //nologo "%temp%elevate.vbs" % ) else ( rd uactest /s /q ) :lbl_SkipElevate rem - rest of batchfile - this should work in any batchfile and generate elevate.vbs only when needed.Anonymous
May 02, 2009
oops the last one was not working... I pasted something wrong... here is the working one: Here is a piece of batch code for elevating a random batchfile I wrote based on this example. It first checks for the uac, then when needed it writes an elevate.vbs to %temp% then calls that file, that on it's turn calls the batchfile it was called from in elevated mode, passing the directory as an argument. The batchfile then changes directory to the arguments location and continues. @echo off rem --- start of batchfile --- rem --- change dir to argument --- if not "%1"=="" ( cd "%" goto :lbl_SkipElevate ) rem --- test uac --- mkdir uactest 2>nul if errorlevel 1 ( goto :lbl_Elevation ) else ( rd uactest /s /q ) goto :lbl_SkipElevate rem --- elevation routine --- :lbl_Elevation set str_ElevName="%temp%elevate.vbs" echo ' // Based on Elevation PowerToys for Windows Vista v1.1 (04/29/2008) > %str_ElevName% echo Set objShell = CreateObject("Shell.Application") >> %str_ElevName% echo Set objWshShell = WScript.CreateObject("WScript.Shell") >> %str_ElevName% echo Set objWshProcessEnv = objWshShell.Environment("PROCESS") >> %str_ElevName% echo strDir = objWshProcessEnv("ELEVATE_DIR") >> %str_ElevName% echo strApp = objWshProcessEnv("ELEVATE_APP") >> %str_ElevName% echo objShell.ShellExecute "" ^& strApp, "" ^& strDir, "", "runas" >> %str_ElevName% set ELEVATE_APP=%~nx0 set ELEVATE_DIR=%cd% start wscript //nologo "%temp%elevate.vbs" % exit rem --- rest of batchfile --- :lbl_SkipElevate echo %~dp0 pause