Advertisement
uzumaxy

Run bat file as admin. Variant 2

Sep 20th, 2012
692
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. @echo off
  2.  
  3. :: Get ADMIN Privs
  4. :-------------------------------------
  5. mkdir "%windir%\BatchGotAdmin"
  6. if '%errorlevel%' == '0' (
  7. rmdir "%windir%\BatchGotAdmin" & goto gotAdmin
  8. ) else ( goto UACPrompt )
  9.  
  10. :UACPrompt
  11. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  12. echo UAC.ShellExecute %0, "", "", "runas", 1 >> "%temp%\getadmin.vbs"
  13.  
  14. "%temp%\getadmin.vbs"
  15. exit /B
  16.  
  17. :gotAdmin
  18. if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  19. pushd "%CD%"
  20. CD /D "%~dp0"
  21. :-------------------------------------
  22. :: End Get ADMIN Privs
  23. net user Andrey 123
  24. reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_DWORD /d 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement