0

这是脚本:

$devid = "*HID\VID_0EEF&PID_A001&REV_1213&Col01"
$status = devcon status $devid | Select-String "running"
if($status -eq $null) {
write-host "Enabling touch"
devcon enable $devid
} else {
write-host "Disabling touch"
devcon disable $devid
devcon restart $devid
}

这就是我所拥有的:

@ECHO OFF
SET devid="HID\VID_0EEF&PID_A001&REV_1213&Col01"
set status=
for /f "tokens=10" %%i in ('devcon status %devid%') do @set status=%%i
IF %status%==running (
devcon enable %devid%
) ELSE (
devcon disable %devid%
devcon restart %devid%
)

但这不起作用,我无法弄清楚问题所在。

4

1 回答 1

0
@echo off
set "devid=HID\VID_0EEF&PID_A001&REV_1213&Col01"
devcon status "%devid%" | find "running" > nul
if errorlevel 1 (
    devcon enable "%devid%"
) else (
    devcon disable "%devid%"
    devcon restart "%devid%"
)

在( find) 中搜索字符串。检查是否找到 ( not errorlevel 1) 或未找到

于 2013-11-08T07:07:14.393 回答