I have the following batch file which identifies my current RS232 port number.
Instead of echo-ing the result (either "Warning" or the Com Port, I would like for the result to be written into a txt file so that I can read it out and work with it from within my Access VBA app.
So if %SerialPort% could be written inside say C:\RSPort.txt
Thanks a lot
Code: Select all
@echo off
setlocal EnableExtensions
set "HardwareID=VID_067B&PID_2303"
set "RegistryPath=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB"
set "ProductName=RS232 cable"
set "DeviceFound=0"
cls
for /F "delims=" %%I in ('%SystemRoot%\System32\reg.exe QUERY "%RegistryPath%\%HardwareID%" 2^>nul') do call :GetPort "%%I"
if "%DeviceFound%" == "0" echo WARNING
echo.
endlocal
pause
goto :EOF
:GetPort
set "RegistryKey=%~1"
if /I not "%RegistryKey:~0,71%" == "%RegistryPath%\%HardwareID%\" goto :EOF
for /F "skip=2 tokens=1,3" %%A in ('%SystemRoot%\System32\reg.exe QUERY "%~1\Device Parameters" /v PortName 2^>nul') do (
if /I "%%A" == "PortName" set "SerialPort=%%B" && goto OutputPort
)
goto :EOF
:OutputPort
%SystemRoot%\System32\reg.exe query HKLM\HARDWARE\DEVICEMAP\SERIALCOMM | %SystemRoot%\System32\findstr.exe /E /I /L /C:%SerialPort% >nul
if errorlevel 1 goto :EOF
set "DeviceFound=1"
set "DeviceNumber=%RegistryKey:~-1%"
cls
echo %SerialPort%
goto :EOF