Advertisement
JacobPaulin

Find & Fix Unquoted Service Paths

Mar 16th, 2023
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2.  
  3. @rem Checking & Prompting for run as administrator
  4. @rem --------------------------------------------------------------------------
  5. @rem Checking for permissions...
  6.  
  7. if "%PROCESSOR_ARCHITECTURE%" equ "amd64" (
  8.     "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system">nul 2>&1
  9. ) else (
  10.     "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system">nul 2>&1
  11. )
  12.  
  13. if '%errorlevel%' neq '0' (
  14.     @rem Administrator permissions not found
  15.  
  16.     echo Requesting administrative privileges...
  17.     goto UACPrompt
  18. ) else (
  19.     @rem Administrator permissions found
  20.    
  21.     goto gotAdmin
  22. )
  23.  
  24. :UACPrompt
  25.     echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  26.     set params= %*
  27.     echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
  28.  
  29.    "%temp%\getadmin.vbs"
  30.    del "%temp%\getadmin.vbs"
  31.    exit /B
  32.  
  33. :gotAdmin
  34.    pushd "%CD%"
  35.    CD /D "%~dp0"
  36. @rem --------------------------------------------------------------------------  
  37.  
  38. set tempFile=%TEMP%\UnquottedPaths.txt
  39.  
  40. if exist %tempFile% del %tempFile%
  41.  
  42. wmic service get name,pathname,startmode,displayname /format:csv | findstr /i auto | findstr /i /v "C:\Windows\\" | findstr /i /v ^""" > %tempFile%
  43.  
  44. for /f "tokens=2,4 delims=," %%a in (%tempFile%) do (
  45.     reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\%%a" /v ImagePath /t REG_EXPAND_SZ /d "\"%%b"\" /f >NUL 2>&1
  46.     echo Fixed path for service %%a,
  47.     echo quoted the following path: %%b
  48.     echo:
  49. )
  50.  
  51. if exist %tempFile% del %tempFile%
  52.  
  53. echo Successfully fixed unquotted paths!
  54.  
  55. echo:
  56. echo [Press any key to close this window]
  57. pause >nul
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement