batch-filedevcon

Batch: How to use "devcon status" return as IF condition?


I am having trouble with my digitizer and pen. The palmrejection detects the pen only when it's like 1cm above the screen.

So I'm trying to make a batch which disables or enables the touchscreen when executed.

devcon disable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

devcon enable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

Currently i have 2 seperate batches with one of the above commands and they work fine. But I want it in 1 file with an IF ELSE clause.

D:
cd D:\Windows Kits\10\Tools\x64
SET /P Test=devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
IF %Test% EQU 1(
devcon disable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
)ELSE(
devcon enable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
)

I tried, but I don't know how to use the status return as IF condition to en- or disable the touchscreen.

C:\WINDOWS\system32>D:

D:\>cd D:\Windows Kits\10\Tools\x64

D:\Windows Kits\10\Tools\x64>SET /P Test=devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

>>devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"

This is returned by cmd when executed. The last line isn't executed, I can still edit it and press enter, then cmd closes.

D:\Windows Kits\10\Tools\x64>devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
HID\ELAN0732&COL01\5&242C8B19&1&0000
    Name: HID-konformer Touchscreen
    Device is disabled.
1 matching device(s) found.

status if device is disabled

D:\Windows Kits\10\Tools\x64>devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
HID\ELAN0732&COL01\5&242C8B19&1&0000
    Name: HID-konformer Touchscreen
    Driver is running.
1 matching device(s) found.

status if device is enabled


Solution

  • To get the output of a command into a variable, use a for /f loop. Filter the line you need (Device is xxxxx) and get the third token (word) from this line:

    for /f "tokens=3" %%a in ('devcon status "@HID\ELAN0732&COL01\5&242C8B19&1&0000"^|find "Device is"') do set "status=%%a"
    echo status is %status%
    

    The rest of your code is not quite correct (batch is a bit picky with spaces) and I changed the if to string comparison to make it safe against an empty %status% variable:

    IF "%status%" == "running" (
      devcon disable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
    ) ELSE (
      devcon enable "@HID\ELAN0732&COL01\5&242C8B19&1&0000"
    )