-1

Is there a batch script or command?

I have tried net user [username] *
and tried net user local group administrators.

Community
  • 1
  • 1
Kaku
  • 1

1 Answers1

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.

Dennis van Gils
  • 3,487
  • 2
  • 14
  • 35
  • If my answer solved your problem you can accept it by clicking the check next to it. If it didn't you can leave a comment and I'll try to help you with your other problems – Dennis van Gils Jan 23 '16 at 13:00