升级的批处理脚本导致firefox崩溃

时间:2015-03-28 00:00:47

标签: windows batch-file uac elevated-privileges

我在这里使用马特的想法。我做的唯一更改是在底部添加两个netstat命令并删除cmd /k,因为这似乎使脚本冻结。这个脚本导致firefox崩溃。我可以请一些关于这种情况发生方式和原因的想法吗?我该如何解决?

How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?

:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************

setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B

:gotPrivileges
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
setlocal & pushd .

REM Run shell as admin (example) - put here code as you like
net stop "Audiosrv"
net start "Audiosrv"

0 个答案:

没有答案