@echo off
set OLDDIR=%CD%
set scriptdir=%~dp0
cd /d %scriptdir%

ver | find "5.1." > NUL &&  goto ver_xp
set isX64=False
echo "Processor architecture is %PROCESSOR_ARCHITECTURE%"
if /I "%Processor_Architecture%"=="AMD64" set isX64=True
if /I "%PROCESSOR_ARCHITEW6432%"=="AMD64" set isX64=True

goto check_permissions

:check_permissions
    echo Administrative permissions required. Detecting permissions...
    net session >NUL 2>&1
    if %errorLevel% == 0 (
        echo "Success: Administrative permissions confirmed."
		goto gotAdmin
    ) else (
        echo "本程序需要管理员权限运行..."
		goto failed
    )
	
:gotAdmin

:ver_win7/vista
echo "Installing MSVC 2010 RunTime..."
.\vcredist_x86.exe /q /norestart
echo "Registring audio_sniffer.dll..."
regsvr32 /s "%scriptdir%\audio_sniffer.dll"
if %errorlevel% neq 0 goto failed

if %isX64%==True (
	.\vcredist_x64.exe /q /norestart
	regsvr32 /s "%scriptdir%\audio_sniffer-x64.dll"
	if %errorlevel% neq 0 goto failed
)

set msg="声音组件安装成功了"
goto end

:ver_xp
set msg="声音组件暂不支持XP系统"
goto end

:failed
set msg="安装发生错误"

:end
echo %msg%

