|
@echo off
ECHO.
ECHO ==========================================
ECHO 以管理员身份运行exe文件
ECHO ==========================================
:init
setlocal DisableDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO ********************************
ECHO 请求 UAC 权限批准……
ECHO ********************************
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & pushd.
cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: 以下为需要运行的批处理文件代码 ::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
reg add "HKCR\exefile\shell\appmanager" /f /v "MUIVerb" /t REG_EXPAND_SZ /d "添加到以管理员身份运行"
reg add "HKCR\exefile\shell\appmanager" /f /v "Icon" /t REG_EXPAND_SZ /d "imageres.dll,77"
reg add "HKCR\exefile\shell\appmanager\Command" /f /ve /t REG_EXPAND_SZ /d "\"%0\" \"%%l\""
MODE CON: COLS=56 LINES=23
TITLE 正在加载EXE文件
CLS
:MAIN
:: 重置变量
SET EXE_DISK=
SET EXENAMEEXA=
SET EXENAMEEXB=
SET NAMESEX=
SET FULLNAME=
SET EX=
:: 当前时间
SET tm1=%time:~0,2%
SET tm2=%time:~3,2%
SET tm3=%time:~6,2%
:: #########################################################################################
:: 获取操作信息
if "%1"=="" GOTO :HELP_EXE
if "%1"=="%~0" GOTO :LOAD_EXE
if "%1"=="%~dp0%~n0%~x0" GOTO :LOAD_EXE
:LOAD_EXE
:: 得到文件路径完整信息
SET EXE_PATH=%1
GOTO SLOAD_EXE
:SLOAD_EXE
:: 获取EXE文件的路径名称等信息
for /f "delims==" %%i in ("%EXE_PATH%") Do (
SET "EXE_DISK=%%~di"
SET "EXENAMEEXA=%%~ni"
SET "EXENAMEEXB=%%~nxi"
SET "NAMESEX=%%~pi%%~nxi"
SET "FULLNAME=%%~dpi%%~nxi"
SET "EX=%%~xi"
)
if /i "%EX%" == ".EXE" (ECHO.&ECHO.正在加载 %EXE_PATH% …) ELSE GOTO :NO_EXE
:: 添加EXE到HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"注册表子键下
echo.
echo.
echo.
echo.
reg add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%FULLNAME%" /t REG_SZ /d "~ RUNASADMIN" /f
echo.
echo.
echo 已成功添加"%FULLNAME%"到HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"注册表了键下
echo.
echo.
pause
exit
:: 保存当前所有引导项列表,如果您不需要此文件可以在其前面添加“::”注译
%BCDEDITS% >"%EXE_PATH%_引导列表预览.txt"
:: #########################################################################################
:HELP_EXE
COLOR 0a
MODE CON: COLS=56 LINES=13
TITLE 拖放您要加载的EXE文件到此 …
ECHO.
ECHO.
ECHO. 请将您要加载的EXE文件拖放到本窗口中!然后按回车键!
ECHO.
ECHO.
ECHO. 注意:EXE不要在带有空格的目录中,EXE文件名没有空格!
ECHO.
ECHO.
SET EXE_PATH=%1
SET /P EXE_PATH=%1
COLOR 0a
MODE CON: COLS=56 LINES=23
TITLE 正在加载EXE文件
CLS
GOTO SLOAD_EXE
:: #########################################################################################
:NO_EXE
COLOR 0a
MODE CON: COLS=56 LINES=13
TITLE %EXE_PATH% 不是EXE可执行文件 …
ECHO.
ECHO. !!!错误 !!!
ECHO.
ECHO.
ECHO. 无法加载 %EXE_PATH%
ECHO.
ECHO. %EXENAMEEXB% 不是EXE可执行文件!!!
ECHO.
ECHO.
ECHO. 请按任意键继续 ……
ECHO.
Pause >nul
SET EXE_DISK=
SET EXENAMEEXA=
SET EXENAMEEXB=
SET NAMESEX=
SET FULLNAME=
SET EX=
GOTO HELP_EXE
:: #########################################################################################
:ON_EXES
COLOR 0a
MODE CON: COLS=56 LINES=13
TITLE %FULLNAME% 已存在 …
REG QUERY "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%FULLNAME%"
ECHO.
ECHO.
ECHO %FULLNAME% 已在HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers子键下 !!!
ECHO.
ECHO.
ECHO.
ECHO.
Pause >nul
SET EXE_DISK=
SET EXENAMEEXA=
SET EXENAMEEXB=
SET NAMESEX=
SET FULLNAME=
SET EX=
goto MAIN
|
|