I'm trying to use SetupDiGetDeviceRegistryProperty to extract the friendly device name of mouse devices but I can't figure it out...
https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
Using a slight modification of the code from here:
http://www.autohotkey.com/board/topic/9 ... inning-up/
I'm able to get a msgbox for a bunch of devices, but not the mice...
Code: Select all
;Adapted from:
;http://stackoverflow.com/questions/4097000/how-do-i-disable-a-system-device-programatically
hModule := DllCall("LoadLibrary", "str", "setupapi.dll")
OnExit, FreeLib
GUID_DEVCLASS_MOUSE = {4d36e96f-e325-11ce-bfc1-08002be10318}
info := DllCall("setupapi.dll\SetupDiGetClassDevsW", "ptr", 0, "ptr", 0, "ptr", 0, "uint", DIGCF_ALLCLASSES := 4)
if (info = -1)
{
Msgbox % "SetupDiGetClassDevs failed: " A_LastError
Exitapp
}
DevInfo_Data(di)
Loop
{
if !DllCall("setupapi.dll\SetupDiEnumDeviceInfo", "ptr", info, "uint", A_Index-1, "ptr", &di)
{
If (A_LastError = 259) ;ERROR_NO_MORE_ITEMS
{
Msgbox % "Could not find the device."
Exitapp
}
else
{
Msgbox % "SetupDiEnumDeviceInfo failed: " A_LastError
Exitapp
}
}
___ := GetDeviceString(info, di, 12)
If (___ <> "")
MsgBox, %___%
if (___ = DeviceName)
break
}
return
F1::
Traytip, Dev State Change, Enabling %DeviceName%
MakeChange(info, di, 1)
return
F2::
Traytip, Dev State Change, Disabling %DeviceName%
MakeChange(info, di, 2)
return
Esc::ExitApp
FreeLib:
DllCall("setupapi.dll\SetupDiDestroyDeviceInfoList", "ptr", info)
DllCall("FreeLibrary", "Ptr", hModule)
ExitApp
return
PropChange_Params(byref pcp, InstallFunction, state)
{
/*
SP_CLASSINSTALL_HEADER
sizeof: 8
0 - cbSize
4 - InstallFunction
SP_PROPCHANGE_PARAMS
sizeof: 20
0 - Install header
8 - StateChange
12 - Scope
16 - HwProfile
*/
VarSetCapacity(pcp, 20)
Numput(8, pcp, 0, "uint"), Numput(InstallFunction, pcp, 4, "uint")
Numput(1, pcp, 12, "uint"), Numput(0, pcp, 16, "uint")
;DICS_ENABLE = 1
;DICS_DISABLE = 2
Numput(state, pcp, 8, "uint")
}
GetDeviceString(info, byref di, propID = 1)
{
;http://msdn.microsoft.com/en-us/library/windows/hardware/ff551967(v=vs.85).aspx
VarSetCapacity(buf, 512), VarSetCapacity(strsz, 4)
r := DllCall("setupapi.dll\SetupDiGetDeviceRegistryPropertyW", "ptr", info, "ptr", &di
, "uint", propID, "ptr", 0, "ptr", &buf, "uint", 512, "ptr", &strsz)
if !r
{
if (A_LastError = 13) ;ERROR_INVALID_DATA
return ""
Msgbox % "SetupDiGetDeviceRegistryProperty failed: " A_LastError
ExitApp
}
return StrGet(&buf, NumGet(strsz, "uint"))
}
MakeChange(info, byref di, newstate)
{
PropChange_Params(pcp, 0x12, newstate)
if !DllCall("setupapi.dll\SetupDiSetClassInstallParams", "ptr", info, "ptr", &di, "ptr", &pcp, "uint", 20)
{
Msgbox % "SetupDiSetClassInstallParams failed: " A_LastError
Exitapp
}
if !DllCall("setupapi.dll\SetupDiChangeState", "ptr", info, "ptr", &di)
{
Msgbox % "SetupDiChangeState failed: " A_LastError
Exitapp
}
}
DevInfo_Data(byref di)
{
/*
SP_DEVINFO_DATA struct
sizeof: 28
0 - cbSize
4 - ClassGuid
20 - DevInst
24 - reserved
*/
VarSetCapacity(di, 24+A_PtrSize,0), Numput(24+A_PtrSize, di, 0, "uint")
}
Code: Select all
str := "{4d36e96f-e325-11ce-bfc1-08002be10318}" ; GUID_DEVCLASS_MOUSE
StringUpper, str, str
COM_Init()
hDIC := COM_GUID4String(DIC, str)
COM_Term()
http://www.autohotkey.com/board/topic/4 ... -for-guid/
but I can't seem to make sense of it, any help greatly appreciated!
thanks
- joel