IsDevPresent v0.0

This little nifty tool can return the number of present devices specified by a Search-String within a device class. 
It is so much simpler and less processor intensive to use, compared to parsing whatever DevCon outputs. 
The comparison is done case insensitive and so does the Windows function to retrieve the ClassGUID for the device class.


You can find all the names of available classes in the registry.
Win2K: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class
Win98: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class
Or you could use DevCon: "devconc.exe classes"

IsDevPrC.exe is the CMD version and IsDevPr.exe is a windowless WinMain version that doesn't output any text at all and is designed to be used in AutoHotkey for minimum memory usage and quick loading and unloading.


Using this is simple.
The 1st argument defines a device class name.
If this doesn't match anything known by the system then -1 is returned, otherwise 0 regardless of how many connected devices are found.
The 2nd argument specifies the search string, every retrieved device string will scanned for this and the number of matches will be returned.
So if you want the number of all connected devices of a class then you can use '\' as all device strings will contain at least one slash. 


Testing the windowless version from the (NT) command prompt is also possible with:
start /wait IsDevPr.exe keyboard \
Then check the return value afterwards with:
echo %errorlevel%

Actually using it in AHK is a equally simple task:
RunWait, IsDevPr mouse HiD,,UseErrorLevel
MsgBox, Found %ErrorLevel% device(s)

It does make a lot sense to combine it with this message listener:
OnMessage(0x219,"WM_DEVICECHANGE") ;this line at start of the script
;the following function sets a oneshot timer for DelayCheckHW
;this is useful as Windows often sends out multiple WM_DEVICECHANGE at once
WM_DEVICECHANGE(wParam,lParam)
{
	if wParam != 7
		return 1
	SetTimer,DelayCheckHW,-110
	return 1
}
;now here's a practical example for a Win98 laptop
;this calls ShowNetworkTray if a certain CardBus LAN adapter was inserted
DelayCheckHW:
RunWait,IsDevPr.exe net PCI\VEN_10EC&DEV_8139,,UseErrorLevel
if ErrorLevel>0
	gosub ShowNetworkTray
;more code omitted from this point


You can use this one liner to compile the windowless version with Open Watcom:
C:\WATCOM\binnt\wcl386.exe /d0 IsDevPr.c -i="C:\WATCOM/h" -l=nt_win


T. Sosnow. <t-sosnow@posteo.com>
Visit QWERTZ-tek at http://qwertz.w10.site/ for my other stuff
April 23, 2026