hipHOPsMuRf 0 Posted September 3, 2010 I have seen scripts here on the forums that detect if a USB thumb drive has been removed from the system but am unable to find anything to detect if a smartcard or eToken has been removed. Is it possible? Any help would be greatly appreciated. Share this post Link to post Share on other sites
hipHOPsMuRf 0 Posted September 4, 2010 Found the solution myself using a few different code snippets found here on the forums. Credit goes to whom it is due. expandcollapse popupGlobal $Paused HotKeySet("{Pause}","TogglePause") $WM_DEVICE_CHANGE = 0x0219 $DBT_DEVNODES_CHANGED = "0x00000007" GUICreate("") GUIRegisterMsg($WM_DEVICE_CHANGE , "MyFunc") Func MyFunc($hWndGUI, $MsgID, $WParam, $LParam) If $WParam == $DBT_DEVNODES_CHANGED Then If($PAUSED <> True)Then tokenChk() EndIf EndIf EndFunc While 1 $GuiMsg = GUIGetMsg() WEnd Func TogglePause() $Paused = NOT $Paused While $Paused sleep(100) ToolTip('Script is "Paused"',0,0) WEnd ToolTip("") EndFunc Func tokenChk() $mcount = 0 $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $colDevices = $objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice") For $objDevice in $colDevices $strDeviceName = $objDevice.Dependent $strQuotes = Chr(34) $strDeviceName = StringReplace($strDeviceName, $strQuotes, "") $arrDeviceNames = StringSplit($strDeviceName, "=") $strDeviceName = $arrDeviceNames[2] $colUSBDevices = $objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & $strDeviceName & "'") For $objUSBDevice in $colUSBDevices If($objUSBDevice.Description == "USB Token")Then $mcount = 1 MsgBox(0,"USB Description",$objUSBDevice.Description) MsgBox(0,$objUSBDevice.Description,$objUSBDevice.Manufacturer) EndIf Next Next If ($mcount<>1)Then MsgBox(0,"Alert!","Token Removed") EndIf EndFunc Share this post Link to post Share on other sites