Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::Here is the complete code. Sorry about that.
- ::::::::::::::::::::::::::::::::::::::::::::
- :: Elevate.cmd - Version 4
- :: Automatically check & get admin rights
- :: see "https://stackoverflow.com/a/12264592/1016343" for description
- ::::::::::::::::::::::::::::::::::::::::::::
- @echo off
- CLS
- ECHO.
- ECHO =============================
- ECHO Running Admin shell
- ECHO =============================
- :init
- setlocal DisableDelayedExpansion
- set cmdInvoke=1
- set winSysFolder=System32
- set "batchPath=%~dpnx0"
- rem this works also from cmd shell, other than %~0
- for %%k in (%0) do set batchName=%%~nk
- set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
- setlocal EnableDelayedExpansion
- :checkPrivileges
- NET FILE 1>NUL 2>NUL
- if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
- :getPrivileges
- if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
- ECHO.
- ECHO **************************************
- ECHO Invoking UAC for Privilege Escalation
- ECHO **************************************
- ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
- ECHO args = "ELEV " >> "%vbsGetPrivileges%"
- ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
- ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
- ECHO Next >> "%vbsGetPrivileges%"
- if '%cmdInvoke%'=='1' goto InvokeCmd
- ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
- goto ExecElevation
- :InvokeCmd
- ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
- ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
- :ExecElevation
- "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
- exit /B
- :gotPrivileges
- setlocal & cd /d %~dp0
- if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
- ::::::::::::::::::::::::::::
- ::START
- ::::::::::::::::::::::::::::
- @echo off
- REM Check if the script is running with administrative privileges
- net session >nul 2>&1
- if %errorLevel% == 0 (
- echo Running with administrative privileges...
- ) else (
- echo Please run this script as an administrator.
- pause
- exit
- )
- REM Kill processes
- taskkill /f /im explorer.exe
- taskkill /f /im TextInputHost.exe
- taskkill /f /im ShellExperienceHost.exe
- taskkill /f /im StartMenuExperienceHost.exe
- REM Pause for a few seconds
- timeout /t 5
- REM Start processes with error handling
- start explorer.exe
- if %errorLevel% neq 0 (
- echo Failed to start explorer.exe
- pause
- exit
- )
- REM Start TextInputHost.exe
- start "TextInputHost.exe" "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\TextInputHost.exe"
- if %errorLevel% neq 0 (
- echo Failed to start TextInputHost.exe
- pause
- exit
- )
- REM Start StartMenuExperienceHost.exe
- start "StartMenuExperienceHost.exe" "C:\Windows\SystemApps\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\StartMenuExperienceHost.exe"
- if %errorLevel% neq 0 (
- echo Failed to start StartMenuExperienceHost.exe
- pause
- exit
- )
- echo All processes started successfully.
- pause
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement