Sign in to follow this  
Followers 0
hipHOPsMuRf

Smartcard / eToken

2 posts in this topic

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



Found the solution myself using a few different code snippets found here on the forums. Credit goes to whom it is due.

Global $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

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0