@ECHO OFF

cd /d %~dp0

ECHO Uninstaling AviSynth...
ECHO =======================================================

SET HasAdminRights=0
FOR /F %%i IN ('WHOAMI /PRIV /NH') DO (
	IF "%%i"=="SeTakeOwnershipPrivilege" SET HasAdminRights=1
)

IF NOT %HasAdminRights%==1 (
	ECHO Error:No admin rights detected. 
	ECHO This script must be run as an Administrator.
	ECHO.
	GOTO END
)

if "%ProgramW6432%" == "" (

reg delete "HKEY_CLASSES_ROOT\CLSID\{E6D6B700-124D-11D4-86F3-DB80AFD98778}" /f
reg delete "HKEY_CLASSES_ROOT\Media Type\Extensions\.avs" /f
reg delete "HKEY_CLASSES_ROOT\.avs" /f
reg delete "HKEY_CLASSES_ROOT\.avsi" /f
reg delete "HKEY_CLASSES_ROOT\avsfile" /f
reg delete "HKEY_CLASSES_ROOT\avs_auto_file" /f
reg delete "HKEY_CLASSES_ROOT\AVIFile\Extensions\AVS" /f
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth" /f

del "%SYSTEMROOT%\System32\AviSynth.dll" /Q 
del "%SYSTEMROOT%\System32\DevIL.dll" /Q 

rmdir "%PROGRAMFILES%\AviSynth+\License" /S /Q
rmdir "%PROGRAMFILES%\AviSynth+\plugins" /S /Q
rmdir "%PROGRAMFILES%\AviSynth+\plugins+" /S /Q
rmdir "%PROGRAMFILES%\AviSynth+\plugins64" /S /Q
rmdir "%PROGRAMFILES%\AviSynth+\plugins64+" /S /Q
del "%PROGRAMFILES%\AviSynth+\Uninstall.cmd" /Q 

) else (

reg delete "HKEY_CLASSES_ROOT\CLSID\{E6D6B700-124D-11D4-86F3-DB80AFD98778}" /f
reg delete "HKEY_CLASSES_ROOT\Media Type\Extensions\.avs" /f
reg delete "HKEY_CLASSES_ROOT\.avs" /f
reg delete "HKEY_CLASSES_ROOT\.avsi" /f
reg delete "HKEY_CLASSES_ROOT\avsfile" /f
reg delete "HKEY_CLASSES_ROOT\avs_auto_file" /f
reg delete "HKEY_CLASSES_ROOT\AVIFile\Extensions\AVS" /f
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Avisynth" /f

reg delete "HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{E6D6B700-124D-11D4-86F3-DB80AFD98778}" /f
reg delete "HKEY_CLASSES_ROOT\Wow6432Node\Media Type\Extensions\.avs" /f
reg delete "HKEY_CLASSES_ROOT\Wow6432Node\.avs" /f
reg delete "HKEY_CLASSES_ROOT\Wow6432Node\.avsi" /f
reg delete "HKEY_CLASSES_ROOT\Wow6432Node\avsfile" /f
reg delete "HKEY_CLASSES_ROOT\Wow6432Node\avs_auto_file" /f
reg delete "HKEY_CLASSES_ROOT\Wow6432Node\AVIFile\Extensions\AVS" /f
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Avisynth" /f

del "%SYSTEMROOT%\System32\AviSynth.dll" /Q 
del "%SYSTEMROOT%\SysWOW64\AviSynth.dll" /Q 
del "%SYSTEMROOT%\System32\DevIL.dll" /Q 
del "%SYSTEMROOT%\SysWOW64\DevIL.dll" /Q 

rmdir "%PROGRAMFILES(x86)%\AviSynth+\License" /S /Q
rmdir "%PROGRAMFILES(x86)%\AviSynth+\plugins" /S /Q
rmdir "%PROGRAMFILES(x86)%\AviSynth+\plugins+" /S /Q
rmdir "%PROGRAMFILES(x86)%\AviSynth+\plugins64" /S /Q
rmdir "%PROGRAMFILES(x86)%\AviSynth+\plugins64+" /S /Q
del "%PROGRAMFILES(x86)%\AviSynth+\Uninstall.cmd" /Q 

)

:END
pause