Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. @echo off &setlocal
  2. :: BatchGotAdmin
  3. :-------------------------------------
  4. REM --> Check for permissions
  5. >nul 2>&1 "%SYSTEMROOT%system32cacls.exe" "%SYSTEMROOT%system32configsystem"
  6.  
  7. REM --> If error flag set, we do not have admin.
  8. if '%errorlevel%' NEQ '0' (
  9. echo Requesting administrative privileges...
  10. goto UACPrompt
  11. ) else ( goto gotAdmin )
  12.  
  13. :UACPrompt
  14. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%getadmin.vbs"
  15. set params = %*:"=""
  16. echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%getadmin.vbs"
  17.  
  18. "%temp%getadmin.vbs"
  19. del "%temp%getadmin.vbs"
  20. exit /B
  21.  
  22. :gotAdmin
  23. pushd "%CD%"
  24. CD /D "%~dp0"
  25. :--------------------------------------
  26. cls
  27. :start
  28. :::
  29. ::: *** Log into a remote computer to execute a command ***
  30. :::
  31. ::: (psexec DEVICE -u USERNAME -p PASSWORD cmd)
  32. :::
  33. ::: PSTOOLS must be installed in the %path%
  34. :::
  35.  
  36. :::
  37. for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A
  38.  
  39. set /p computerName="Enter computer/server name: "
  40. echo "Enter the domain of your admin username:"
  41. echo =========================
  42. echo Enter '1' for domain1
  43. echo Enter '2' for domain2
  44. echo Enter '3' for domain3
  45. echo =========================
  46.  
  47. set /p domainName=
  48. if %domainName% == 1 (
  49. set domainName = "domain1"
  50. goto continue
  51. )
  52. if %domainName% == 2 (
  53. set domainName = "domain2"
  54. goto continue
  55. )
  56. if %domainName% == 3 (
  57. set domainName = "domain3"
  58. goto continue
  59. ) else (
  60. goto choice
  61. )
  62.  
  63. :continue
  64. set /p userName="Enter your Admin username: "
  65. powershell -Command $pword = read-host "Enter password " -AsSecureString ; $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword) ; [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) > .tmp.txt & set /p password=<.tmp.txt & del .tmp.txt
  66. psexec \%computerName% -u %domainName%%userName% -p %password% cmd
  67. :choice
  68. set choice=
  69. set /p choice="Do you want to restart this file? Press 'y' for Yes or 'n' for No then Press ENTER: "
  70. if not '%choice%'=='' set choice=%choice:~0,1%
  71. if '%choice%'=='y' goto start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement