Morthawt Posted September 24, 2017 Posted September 24, 2017 Someone here gave me some help in order to detect if my Yubikey is inserted or not, by checking the Windows system for all "keyboard" devices for the presence of the serial number of my Yubikey. Then once unplugged and found to be missing, take some action like lock the PC. The problem is it does not work with the newer Yubikeys because, I think, they act as smartcards or something. So the code looking for a keyboard is no good. There was some kind of tool which I used to help me find what to search for I think, I do not remember. Here is the function which did the original checking, but I am totally clueless on how to tweak it to again be able to find the serial number of my new (no longer acting as a keyboard) Yubikey. Func CheckForYubikey($input) $Output = "" $object = ObjGet("winmgmts:\\" & $strComputer & "\ROOT\CIMV2") $items = $object.ExecQuery("SELECT DeviceID FROM Win32_Keyboard", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($items) Then For $objItem In $items FileWriteLine('test.txt', $objItem.DeviceID) If StringInStr($objItem.DeviceID, $YubikeySerialNumber) Then Return True Next Else Return False EndIf Return False EndFunc ;==>CheckForYubikey Any help would be appreciated. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials.
ripdad Posted September 25, 2017 Posted September 25, 2017 I doubt WMI can return a serial number for your USB device. About the most it would be able to do is give you the Device ID, which is not what you want. Perhaps the manufacturer has software that can do this job. "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Morthawt Posted September 25, 2017 Author Posted September 25, 2017 Well it was providing the serial number as part of what ever it was. But now it no longer works for the new Yubikeys. I would need to know the new device type and possibly a different thing that contains the serial number in it to check. Here is what the preferences of the Yubikey personalisation tool says: Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials.
ripdad Posted September 25, 2017 Posted September 25, 2017 Hmm. Some manufacturers embed part or all of the serial number in their device id strings, but this is usually rare. You could get the PNPDeviceID string from Win32_PnPEntity. Or you could get it from the registry with RegRead under: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now