@echo off

REM The determination of whether you are running in administrator
openfiles > NUL 2>&1 
if NOT %ERRORLEVEL% EQU 0 goto NotAdmin 
goto AdminOK
 
:NotAdmin 
echo Please operate with administrative privileges
pause
exit 0

:AdminOK

REM Deal because the path would change in the Run with administrative
cd /d %~dp0

REM
REM ShotNavi W1-GL PC TOOL Setup
REM

REM Check CP210x of the driver is on
echo CP210x of the driver will confirm that it has been installed.

REM Go to FOUND When you find
for /F "usebackq tokens=1,2,*" %%I in (`driverquery 2^>nul`) do if "%%I"=="silabenm" goto FOUND
REM Move directly to CP210X installation and did not see the driver
echo;
echo CP210x driver was not found. Run the installation.

REM Start each of the installer to determine the 32bit 64bit
set REGKEY=HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
set REGVALUE=PROCESSOR_ARCHITECTURE
set PA=
set CP210XPATH=.\CP210x_Windows_Drivers\
for /F "usebackq tokens=1,2,*" %%I in (`reg query "%REGKEY%" /v %REGVALUE% 2^>nul`) do if "%%I"=="%REGVALUE%" set PA=%%K
if "%PA%"=="x86" (
	echo;
	echo Run the installation of the 32bit version driver of CP210x.
	%CP210XPATH%CP210xVCPInstaller_x86.exe
) else if "%PA%"=="AMD64" (
	echo;
	echo Run the installation of the 64bit version driver of CP210x.
	%CP210XPATH%CP210xVCPInstaller_x64.exe
) else if "%PA%"=="IA64" (
	echo;
	echo Run the installation of the 64bit version driver of CP210x.
	%CP210XPATH%CP210xVCPInstaller_x64.exe
) else (
	echo;
	echo Could not 32bit / 64bit judgment of the OS. Please install manually.
	echo;
	pause
	exit
)

:INSTMESSAGE
REM Message after installation
echo;
echo During uninstall, the uninstall of ShotNavi W1-GL PC tool, drivers will not be removed at the same time.
echo;
pause
goto END

:FOUND
echo;
echo We have confirmed the installation of the CP210x driver.

:END
echo;

REM つづいて SN_W1-GL PC Tool のインストールへ
echo;
echo Run the installation of ShotNavi W1-GL / AS PC Tool.
.\SN_W1-GL\setup.exe

