Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off &setlocal
- :: BatchGotAdmin
- :-------------------------------------
- REM --> Check for permissions
- >nul 2>&1 "%SYSTEMROOT%system32cacls.exe" "%SYSTEMROOT%system32configsystem"
- REM --> If error flag set, we do not have admin.
- if '%errorlevel%' NEQ '0' (
- echo Requesting administrative privileges...
- goto UACPrompt
- ) else ( goto gotAdmin )
- :UACPrompt
- echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%getadmin.vbs"
- set params = %*:"=""
- echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%getadmin.vbs"
- "%temp%getadmin.vbs"
- del "%temp%getadmin.vbs"
- exit /B
- :gotAdmin
- pushd "%CD%"
- CD /D "%~dp0"
- :--------------------------------------
- cls
- :start
- :::
- ::: *** Log into a remote computer to execute a command ***
- :::
- ::: (psexec DEVICE -u USERNAME -p PASSWORD cmd)
- :::
- ::: PSTOOLS must be installed in the %path%
- :::
- :::
- for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A
- set /p computerName="Enter computer/server name: "
- echo "Enter the domain of your admin username:"
- echo =========================
- echo Enter '1' for domain1
- echo Enter '2' for domain2
- echo Enter '3' for domain3
- echo =========================
- set /p domainName=
- if %domainName% == 1 (
- set domainName = "domain1"
- goto continue
- )
- if %domainName% == 2 (
- set domainName = "domain2"
- goto continue
- )
- if %domainName% == 3 (
- set domainName = "domain3"
- goto continue
- ) else (
- goto choice
- )
- :continue
- set /p userName="Enter your Admin username: "
- 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
- psexec \%computerName% -u %domainName%%userName% -p %password% cmd
- :choice
- set choice=
- set /p choice="Do you want to restart this file? Press 'y' for Yes or 'n' for No then Press ENTER: "
- if not '%choice%'=='' set choice=%choice:~0,1%
- if '%choice%'=='y' goto start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement