-1

有批处理脚本或命令吗?

我已经尝试过 net user [username] *
并尝试过 net user local group administrators。

4

1 回答 1

1

If you want to change from normal user to admin, you could use this:

@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if %errorlevel% NEQ 0 (GOTO askAdmin)
GOTO gotAdmin


:askAdmin
::batch is being ran as normal user
echo I'm not an admin yet
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "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"
::batch is being ran as admin
echo Now I'm an admin!
pause

You should put all the code that needs to be ran below the :askAdmin label, else it get's executed twice.

于 2016-01-23T10:17:30.653 回答