非常简单,我很难find答案。
serverfault 以前帮助我find一种方法来自动化Windows更新而不使用WSUS。 它的工作非常出色,但要在networking上运行,您必须首先安装共享驱动器。 这是非常简单的XP,因为你只是安装驱动器并运行更新。
不过在Vista和W7上,这一切都必须通过提升权限才能正常工作。 UAC帐户无法看到普通用户安装的networking驱动器,所以为了使所有的工作,我必须从一个升级的shell通过net use挂载共享。 我想自动安装这个共享,并通过一个简单的.bat文件启动更新。
我可能只是指示每个人在.bat文件上右键单击“以pipe理员身份运行”,但我想保持尽可能简单的事情,并让.bat自动提示用户升级他们的权限。
由于这些计算机不属于我们,所以我不能指望安装Powershell这样的任何东西,所以规定任何解决scheme,几乎不得不依赖RTM Vista安装中包含的东西。 我希望我大多在这里失去一些明显的东西。 🙂
http://technet.microsoft.com/en-us/magazine/2007.06.utilityspotlight.aspx
编辑:如果你给客户一个单独的文件运行,为什么不创build一个自解压RAR与WinRAR并设置SFX选项中的“需要pipe理员”标志? 这可以免除你只有一个文件的限制,你可以拥有所有你需要的资源。
或者使用您最喜爱的SFX工具来使用SFX,并使用上面的提升工具。
如果你准备转换到PowerShell,这是更容易做到。 这是我的“ Elevate-Process.ps1 ”脚本(在我的configuration文件中用su作为别名):
# Updated elevate function that does not need Elevate PowerToys # From http://devhawk.net/2008/11/08/My+ElevateProcess+Script.aspx $psi = new-object System.Diagnostics.ProcessStartInfo $psi.Verb = "runas" # If passed multiple commands, or one (that isn't a folder) then execute that command: if (($args.Length -gt 1) -or (($args.length -eq 1) -and -not (test-path $args[0] -pathType Container))) { $file, [string]$arguments = $args; $psi.FileName = $file $psi.Arguments = $arguments [System.Diagnostics.Process]::Start($psi) | out-null return } # If from console host, handle case of one argyment that is # a folder, to start in that folder. Otherwise start in current folder. if ($host.Name -eq 'ConsoleHost') { $psi.FileName = (Get-Command -name "PowerShell").Definition if ($args.length -eq 0) { $psi.Arguments = "-NoExit -Command &{set-location '" + (get-location).Path + "'}" } else { $psi.Arguments = "-NoExit -Command &{set-location '" + (resolve-path $args[0]) + "'}" } [System.Diagnostics.Process]::Start($psi) | out-null return } # Otherwise this is some other host (which cannot be assumed to take parameters). # So simplely launch elevated. $psi.FileName = [system.diagnostics.process]::getcurrentprocess().path $psi.Arguments = "" [System.Diagnostics.Process]::Start($psi) | out-null
也可以在PSH中检测boost(因此您可以检查boost,然后在需要时boost):
$wid=[System.Security.Principal.WindowsIdentity]::GetCurrent() $prp=new-object System.Security.Principal.WindowsPrincipal($wid) $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator $IsAdmin=$prp.IsInRole($adm) if ($IsAdmin) { $host.UI.RawUI.Foregroundcolor="Red" write-host "`n** Elevated Session **`n" -foreground $_errorColour -background $_errorBackound }
这里是我想出的一个例子脚本,我希望它能帮助别人。 这是一个bat文件,提示用户许可,然后升级自己。 它输出一些vbscript触发UAC提示,然后重新运行bat文件提升… http://jagaroth.livejournal.com/63875.html
这是你需要的: http : //sites.google.com/site/eneerge/home/BatchGotAdmin
FusionInventory.org是一个开源的解决scheme,主要由小修理店使用。 它可以像你的个人遥控窗口更新。
这些解决scheme都不能用于需要了解命令行参数的.cmd文件。 把它放在.cmd文件的开头,所有的问题都将被解决。 (这是为未来的人浏览这个线程[我已经testing了这个在Windows XP中,7 Vista和8; x86 + x64]):
@echo off NET SESSION >nul 2>&1 && goto noUAC title. set n=%0 %* set n=%n:"=" ^& Chr(34) ^& "% echo Set objShell = CreateObject("Shell.Application")>"%tmp%\cmdUAC.vbs" echo objShell.ShellExecute "cmd.exe", "/c start " ^& Chr(34) ^& "." ^& Chr(34) ^& " /d " ^& Chr(34) ^& "%CD%" ^& Chr(34) ^& " cmd /c %n%", "", "runas", ^1>>"%tmp%\cmdUAC.vbs" echo Not Admin, Attempting to elevate... cscript "%tmp%\cmdUAC.vbs" //Nologo del "%tmp%\cmdUAC.vbs" exit /b :noUAC ::-----Normal Batch Starts Here---------------------
正如@emilio所说,这个脚本是可以的,但它不接受任何参数。 这里修改后的脚本与参数兼容:
:: BatchGotAdmin :------------------------------------- REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo args = "" >> "%temp%\getadmin.vbs" echo For Each strArg in WScript.Arguments >> "%temp%\getadmin.vbs" echo args = args ^& strArg ^& " " >> "%temp%\getadmin.vbs" echo Next >> "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", args, "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" %* exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0" :--------------------------------------
如果您不能依赖于正在安装的Powershell,则可以在StackOverflow上使用此解决scheme:
使用batch file自动提升UAC
它不需要任何东西来安装和运行。 如果您需要保留命令行参数,请考虑此更新。
你尝试过runas命令吗?