@echo off
cls

set log="%~dp0\AxisIPComponents_x32_deltrace.log"
del %log% >nul 2>nul
set err="%~dp0\err.log"
set er2="%~dp0\er2.log"

set titl=Unregister AXIS components(Media Parser,Joystick) (x32) on 32\64-bit OS.
echo %titl%
ver
echo %date% %time:~0,-3%
echo.

@echo %titl% >%err%
if exist %err% goto start_action
echo.
echo *******************************************************
echo ERROR! You do not have rights to unregister components.
echo *******************************************************
echo.
pause
goto :end

:start_action
del %err% >nul 2>nul

if %PROCESSOR_ARCHITECTURE%==AMD64 goto LABEL_x64
if %PROCESSOR_ARCHITECTURE%==IA64 goto LABEL_x64
if defined PROCESSOR_ARCHITEW6432 goto LABEL_x64

set srcdir=%CommonProgramFiles%\AxisIPComponents
set regsvr=%systemroot%\System32\regsvr32.exe
goto LABEL_REG

:LABEL_x64
set srcdir=%CommonProgramFiles(x86)%\AxisIPComponents
set regsvr=%systemroot%\SysWoW64\regsvr32.exe

:LABEL_REG

set src_amp="%srcdir%\AxisMediaParser.dll"
set src_flt="%srcdir%\AxisRTPSrcFilter.ax"
set src_jst="%srcdir%\AxisJoystickModule.dll"
set src_add="%srcdir%\AxisIPComponents_x32_add.bat"
set src_del="%srcdir%\AxisIPComponents_x32_del.bat"

echo.
echo Unregistering Axis Components

%regsvr% /u %src_amp% /s >%err% 2>%er2%
set ertext=[%regsvr% /u %src_amp%] error = %ErrorLevel%
if ErrorLevel 1 goto exit_err

%regsvr% /u %src_flt% /s >%err% 2>%er2%
set ertext=[%regsvr% /u %src_flt%] error = %ErrorLevel%
if ErrorLevel 1 goto exit_err

%regsvr% /u %src_jst% /s >%err% 2>%er2%
set ertext=[%regsvr% /u %src_jst%] error = %ErrorLevel%
if ErrorLevel 1 goto exit_err

del %src_amp% >nul 2>nul
del %src_flt% >nul 2>nul
del %src_jst% >nul 2>nul
del %src_add% >nul 2>nul

@echo.
echo OK! Axis components were unregistered successfully.
echo.
del %err% >nul 2>nul
del %er2% >nul 2>nul
pause
del %src_del% >nul 2>nul
goto :end

:exit_err
@echo %titl% >%log%
ver >>%log%
@echo %date% %time:~0,-3% >>%log%
@echo %ertext% >>%log%
if exist %err% copy %log%+%err% %log% >nul
if exist %er2% copy %log%+%er2% %log% >nul
echo.
echo ************************************************
echo An error occurred while unregistering components.
echo See the log: %log%
echo ************************************************
echo.
del %err% >nul 2>nul
del %er2% >nul 2>nul
pause
:end


