Skip to content

Instantly share code, notes, and snippets.

@sasapurin
Created July 28, 2019 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasapurin/7fbe4fe304fd627a4131d995bbfec6fe to your computer and use it in GitHub Desktop.
Save sasapurin/7fbe4fe304fd627a4131d995bbfec6fe to your computer and use it in GitHub Desktop.
CHECK STATUS and RESTART of USB Device
REM This Script Need the devcon.exe (Include Microsoft WDK)
echo off
setlocal
REM Make Tempfile PATH
set TMP_FILE=%~dp0tmp_status.log
REM Define USB Device ID
set USB_DEV_ID="USB\VID_0590&PID_0081&REV_0109"
REM Run the Get STATUS of USB Device
%windir%\devcon.exe status %USB_DEV_ID% > %TMP_FILE%
REM Check STATUS. and Excec RESTART
find /i "Driver is running." %TMP_FILE% > nul
if not %ERRORLEVEL% equ 0 (
%windir%\devcon.exe restart %USB_DEV_ID% > %TMP_FILE%
if exist %TMP_FILE% ( del %TMP_FILE% )
exit /b 1
)
if exist %TMP_FILE% ( del %TMP_FILE% )
endlocal
exit /b 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment