Advertisement
KKthebeast8

Untitled

Nov 14th, 2023
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Winbatch 3.14 KB | Fixit | 0 0
  1. ::Here is the complete code. Sorry about that.
  2.  
  3. ::::::::::::::::::::::::::::::::::::::::::::
  4. :: Elevate.cmd - Version 4
  5. :: Automatically check & get admin rights
  6. :: see "https://stackoverflow.com/a/12264592/1016343" for description
  7. ::::::::::::::::::::::::::::::::::::::::::::
  8.  @echo off
  9.  CLS
  10.  ECHO.
  11.  ECHO =============================
  12.  ECHO Running Admin shell
  13.  ECHO =============================
  14.  
  15. :init
  16.  setlocal DisableDelayedExpansion
  17.  set cmdInvoke=1
  18.  set winSysFolder=System32
  19.  set "batchPath=%~dpnx0"
  20.  rem this works also from cmd shell, other than %~0
  21.  for %%k in (%0) do set batchName=%%~nk
  22.  set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
  23.  setlocal EnableDelayedExpansion
  24.  
  25. :checkPrivileges
  26.   NET FILE 1>NUL 2>NUL
  27.   if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
  28.  
  29. :getPrivileges
  30.   if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
  31.   ECHO.
  32.   ECHO **************************************
  33.   ECHO Invoking UAC for Privilege Escalation
  34.   ECHO **************************************
  35.  
  36.   ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
  37.   ECHO args = "ELEV " >> "%vbsGetPrivileges%"
  38.   ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
  39.   ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
  40.   ECHO Next >> "%vbsGetPrivileges%"
  41.  
  42.   if '%cmdInvoke%'=='1' goto InvokeCmd
  43.  
  44.   ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
  45.   goto ExecElevation
  46.  
  47. :InvokeCmd
  48.   ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
  49.   ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
  50.  
  51. :ExecElevation
  52.  "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
  53.  exit /B
  54.  
  55. :gotPrivileges
  56.  setlocal & cd /d %~dp0
  57.  if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)
  58.  
  59.  ::::::::::::::::::::::::::::
  60.  ::START
  61.  ::::::::::::::::::::::::::::
  62.  
  63. @echo off
  64. REM Check if the script is running with administrative privileges
  65. net session >nul 2>&1
  66. if %errorLevel% == 0 (
  67.     echo Running with administrative privileges...
  68. ) else (
  69.     echo Please run this script as an administrator.
  70.     pause
  71.     exit
  72. )
  73.  
  74. REM Kill processes
  75. taskkill /f /im explorer.exe
  76. taskkill /f /im TextInputHost.exe
  77. taskkill /f /im ShellExperienceHost.exe
  78. taskkill /f /im StartMenuExperienceHost.exe
  79.  
  80. REM Pause for a few seconds
  81. timeout /t 5
  82.  
  83. REM Start processes with error handling
  84. start explorer.exe
  85. if %errorLevel% neq 0 (
  86.     echo Failed to start explorer.exe
  87.     pause
  88.     exit
  89. )
  90.  
  91. REM Start TextInputHost.exe
  92. start "TextInputHost.exe" "C:\Windows\SystemApps\MicrosoftWindows.Client.CBS_cw5n1h2txyewy\TextInputHost.exe"
  93. if %errorLevel% neq 0 (
  94.     echo Failed to start TextInputHost.exe
  95.     pause
  96.     exit
  97. )
  98.  
  99. REM Start StartMenuExperienceHost.exe
  100. start "StartMenuExperienceHost.exe" "C:\Windows\SystemApps\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\StartMenuExperienceHost.exe"
  101. if %errorLevel% neq 0 (
  102.     echo Failed to start StartMenuExperienceHost.exe
  103.     pause
  104.     exit
  105. )
  106.  
  107. echo All processes started successfully.
  108. pause
  109. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement