@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\ COPY %~sdp0\ocx\WebOffice.ocx %systemroot%\syswow64\

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

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


%~sdp0\office\certmgr -add -c %~sdp0\office\office.cer -s root

regedit.exe /s %~sdp0\tool\curruser.reg

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

start %~sdp0\tool\firefoxplugin.exe

reg add "HKEY_CLASSES_ROOT\WebOffice" /v "" /d "WebOfficeProtocol" /t REG_SZ /f 
reg add "HKEY_CLASSES_ROOT\WebOffice" /v "URL Protocol" /d  "%~sdp0\tool\WebOfficeBrowser.exe" /t REG_SZ /f
reg add "HKEY_CLASSES_ROOT\WebOffice\DefaultIcon" /v "" /d "%~sdp0\tool\WebOfficeBrowser.exe,1" /t REG_SZ /f
reg add "HKEY_CLASSES_ROOT\WebOffice\shell\open\command" /v "" /d "\"%~sdp0\tool\WebOfficeBrowser.exe\",\"%%1\"" /t REG_SZ /f 
 
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
if exist %~sdp0\tool\WebOffice.exe ( 
COPY %~sdp0\tool\WebOffice.exe "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
if exist "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\WebOffice.exe" (
start /d "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" WebOffice.exe ) )
) else (
	reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v WebOffice /t REG_SZ /d %~sdp0tool\WebOffice.exe /f
		
	if exist %~sdp0\tool\WebOffice.exe ( 
	start /d %~sdp0tool WebOffice.exe)

)
