@echo off
CLS 
:init
setlocal DisableDelayedExpansion

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 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%"

ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"

"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %*

exit /B

:gotPrivileges

setlocal & pushd .

cd /d %~dp0

if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

if exist %systemroot%\syswow64\WebOffice.OCX del %systemroot%\syswow64\WebOffice.ocx  /f /q 

if exist %systemroot%\syswow64\WebOffice.OCX %systemroot%\syswow64\regsvr32.exe -u -s %systemroot%\syswow64\WebOffice.OCX

regsvr32 %~sdp0\ocx\weboffice.ocx /s

reg delete "HKEY_CLASSES_ROOT\WebOffice" /f 

start %~sdp0tool\uninstall.exe

if exist "%systemroot%\syswow64\" (
if exist "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WebOffice.exe" (
del "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WebOffice.exe" /f /q)  
) else (
	if exist %~sdp0\tool\WebOffice.exe (
	reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run  /v WebOffice /f )
	 	
)

