::::::::::::::::::::::::::::::::::::::::::::::::::
:: SbieStop_priv.cmd
::
:: Stops Sandboxie services/tasks ... auto-elevate
:: ↑
:: thanks
::
:: Stops CONNECT Client and services/tasks ... auto-elevate
::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off
CLS
ECHO.
ECHO =============================
ECHO Running Admin shell
ECHO =============================

:init
setlocal DisableDelayedExpansion
set cmdInvoke=1
set winSysFolder=System32
set "batchPath=%~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 Stopping Sandboxie services/tasks ...

echo Stopping Print Spooler services/tasks ...
echo.

net stop spooler

echo Delete Renamed Backup ...
echo.

::ROOT of 64-bit file is valid on Windows Version 2004 (OS Build 19041.1) 
::and supposed to be valid on other Win10 Builds

del "C:\Windows\System32\spool\drivers\x64\3\acpdfui600.dll.org" /Q

echo Rename original AMYUNI-AmyuniDocumentConverter600 ...
echo.

ren "C:\Windows\System32\spool\drivers\x64\3\acpdfui600.dll" "acpdfui600.dll.org" 

echo copy patched AMYUNI-AmyuniDocumentConverter600 ...
echo.

xcopy "%~dp0acpdfui600.dll" "C:\Windows\System32\spool\drivers\x64\3" /Y

echo Start Print Spooler services/tasks ...
echo.

net start spooler

pause

@exit



::::::::::::::::::::::::::::::::::::::::::::::::::
:: Reference & Credit :
:: How can I auto-elevate my batch file, so that it requests from UAC administrator rights if required?
:: https://stackoverflow.com/questions/7044985/how-can-i-auto-elevate-my-batch-file-so-that-it-requests-from-uac-administrator/12264592#12264592
::::::::::::::::::::::::::::::::::::::::::::::::::
