Detect touch hardware using VBScript

0

1

I am looking for a way to detect installed touch hardware using VBScript. My script doesn't work.

This script is intended to look for a pointing device and echo accordingly.

    On Error Resume Next
    strComputer = "." 
   WScript.Echo "=========================================="
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PointingDevice")
 For Each objItem In colItems
    TouchDevice = objItem.PointingType
    if TouchDevice = 8 then
        Wscript.Echo "Found touch based hardware"
        WScript.Echo "=========================================="
    Else
        Wscript.Echo "No Touch based hardware found"
        WScript.Echo "=========================================="
    End If
Next

Computer : Dell 15R 5537 Touchscreen Laptop with windows 8 Enterprise.
Pointing Device : Touch Screen, mouse, Touch Pad
How I run the script: Double click the .vbs file or run it via Command Prompt
What happens: As per my script, if TouchDevice == objItem.PointingType == 8, it should output that touch hardware was found but it keeps outputting no touch hardware found.

Reference : WMI Class win32_PointingDevice

pun

Posted 2014-11-24T04:50:51.590

Reputation: 5 311

i wasn't sure how to do it earlier, now i just need to make sure i am doing it right !. – pun – 2014-11-27T20:06:01.443

Is your objective simply to detect the presence of any touch-based pointing device and report whether or not one was found? It would be more appropriate to wait until you have the device and try it. If it doesn't work, there would be a basis to diagnose the problem. It is difficult for someone to look at a script and envision any and all theoretical problems it might have. The script could have some subtle error that doesn't get noticed but a failure would make it obvious. You are basically asking for opinion at this stage, which isn't consistent with the site's objectives. – fixer1234 – 2014-11-27T22:22:35.790

This script does not work. It failed to detect touch screen. Can i get some directions now ? – pun – 2014-12-04T05:19:41.017

Can you provide some supplementary information? computer model and OS? Pointing device? How do you run the script? What happens when you run the script? – fixer1234 – 2014-12-04T05:24:55.443

Did you confirm that your device indeed reports the value 8? I tried this on a lenovo win8 tablet and it will report 2 (=unknown) as value for PointingType – Syberdoor – 2015-01-02T14:36:28.717

Yes, as per http://msdn.microsoft.com/en-us/library/aa394356%28v=vs.85%29.aspx it should indeed report 8.

– pun – 2015-01-03T13:16:13.667

Answers

1

Unfortunately, as you've seen, the win32_PointingDevice structure isn't used correctly.

You can still do it though, by parsing the win32_PnPEntity instead for "touch".

On Error Resume Next
strComputer = "." 
WScript.Echo "=========================================="

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity")
For Each objItem In colItems
    If InStr(1, objItem.Description , "touch", 1) > 0 Then
        Wscript.Echo "Found touch based hardware: " & objItem.PnPDeviceID
        WScript.Echo "=========================================="
    End If
Next

This does pretty much the same thing as your sample attempt but looks at the object description of every PnP device for the word "touch" and lists that object.

shawn

Posted 2014-11-24T04:50:51.590

Reputation: 612