Turning device off by command line?

June 1, 2009 at 13:31:19
Specs: Windows XP
I can't get this batch file to work:
FOR /F "tokens=* delims=: " %%R IN ('devcon status *DEV_1677* ^| FIND "running"') DO SET STATUS=%%R
IF %STATUS% == "Driver is running."
devcon disable *DEV_1677*

Any help is appreciated


See More: Turning device off by command line?

Report •


#1
June 1, 2009 at 22:16:18
devcon status *DEV_1677* | FIND "running"

if not errorlevel 1 devcon disable *DEV_1677*


Report •

#2
June 2, 2009 at 05:14:11
Thank you! How could I expand it to be a toggle for said device?
Something like this?

:Status
FOR /F "tokens=* delims=: " %%R IN ('devcon status *DEV_1677* ^| FIND "running"') DO SET STATUS=%%R
if not errorlevel 1 GOTO DISABLE ELSE GOTO ENABLE

:DISABLE
devcon disable *DEV_1677*
GOTO END

:ENABLE
devcon enable *DEV_1677*
GOTO END

:End


Report •

#3
June 2, 2009 at 05:24:30
the for loop is not needed

@echo off & setlocal
set dev=*DEV_1667*
devcon status %dev%|FIND "running">nul 2>&1 && (goto:disable %dev%) || goto:enable %dev%
goto:eof

:enable
devcon enable %*
goto:eof

:disable
devcon disable %*


Report •

Related Solutions

#4
June 2, 2009 at 05:52:23
Thanks so much! Works great!

Report •


Ask Question