本帖最后由 citygun 于 2016-8-17 15:33 编辑
我刚好也写了个安装打印机的批处理,在win10环境下安装批处理要提权后才可以,可以参考软媒魔方的代码进行提权操作。域环境没有测试,你可以试试。- ::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: 软媒魔方自动添加批处理文件管理员权限::
- ::::::::::::::::::::::::::::::::::::::::::::::::::::
-
- @echo off
- CLS
- ECHO.
- ECHO ================================
- ECHO 软媒魔方获取批处理文件管理员权限
- ECHO ================================
- CLS & COLOR 4F
- :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)
复制代码 提权后下面就可以写自己的代码了。 |