欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

winsw 服务权限获取

程序员文章站 2022-03-04 15:03:30
...

@echo off

@echo 取得当前目录

pushd "%cd%"

cd ..

set pard=%cd%

popd

echo 上一层目录为%pard%

echo 当前目录为%cd%

@echo off

pushd "%cd%"

cd ..

set pard=%cd%

popd

 

 

@echo off

CLS

ECHO.

ECHO ================================

ECHO 获取批处理文件管理员权限

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)

ECHO 取得权限成功

 

ECHO 开始安装文件管理系统服务并开机启动 进入winsw 下载文件的目录 开启服务