Nine Posted November 19, 2018 Posted November 19, 2018 ya you change the if statement, i didnt invest most time understanding your detailed needs, if it is the contrary. change <> with = “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Iznogoud Posted November 20, 2018 Author Posted November 20, 2018 1 hour ago, Nine said: ya you change the if statement, i didnt invest most time understanding your detailed needs, if it is the contrary. change <> with = This is the code i am working on now, and it seems to work. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3> #include <WinAPISys.au3> Opt ("MustDeclareVars", 1) Local $data While 1 Local $dvcn = Run(@comspec & ' /c devcon.exe hwids * | findstr "HID\VID_1050&PID_0114&REV_0340&MI_01"', _ @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) sleep(3000) $data &= StdoutRead($dvcn) if $data = "" then _WinAPI_LockWorkStation() Exit Else $data = "" EndIf ConsoleWrite("USB Drive connected" & @CRLF ) WEnd But i don't know if this is efficient or there is a better way. The sleep of 3000 is nessecary for running the compsec on a heavy load system. Sometimes it does a random lock from the OS... One problem i had now was the disconnecting from the Yubikey / USB Device and the ConsoleWrite stopped, but the screen wasn't locked I hope this was a one timer.
Nine Posted November 20, 2018 Posted November 20, 2018 you told me you wanted to run it every second, and now you put a 3 secs sleep. Second the while, should be around the $data &= as you will miss some read. Bring back my script cause yours ain't gonna work. If you want to loop you must create another one around the whole script. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Iznogoud Posted November 20, 2018 Author Posted November 20, 2018 9 hours ago, Nine said: you told me you wanted to run it every second, and now you put a 3 secs sleep. Second the while, should be around the $data &= as you will miss some read. Bring back my script cause yours ain't gonna work. If you want to loop you must create another one around the whole script. Yes i would like to run it every sec. but then it randomly locks my screen and i think this is happening because the comspec part with the findstr is not ready yet in 1 sec. That is the reason i made it 3 sec. But i will change it back, but then it doesn't work correctly.
Nine Posted November 20, 2018 Posted November 20, 2018 I just tested it extensively with a usb memory key. And the problem seems that stdoutread is interfering with findstr when it reads too rapidly. So I changed the sleep (25) to a sleep (250) and never got a glitch since. As i said previously, create another while starting just before the run and put the Wend after a sleep (3000) at the very end. And FYI, I tested the solution that I proposed initially with a txt file, and I get about the same load on the CPUs.... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Iznogoud Posted November 20, 2018 Author Posted November 20, 2018 (edited) #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Constants.au3> #include <WinAPISys.au3> Opt ("MustDeclareVars", 1) While 1 Local $data ="" Local $dvcn = Run(@comspec & ' /c devcon.exe hwids * | findstr "HID\VID_1050&PID_0114&REV_0340&MI_01"', _ @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) sleep(1000) While True $data &= StdoutRead($dvcn) If @error Then ExitLoop Sleep(250) WEnd ;Msgbox (0,"",$data) if $data = "" then _WinAPI_LockWorkStation() WEnd I needed to add sleep(1000) after the Run command because sometimes when you stress out the CPU it will lock the computer even when the drive is still connected. EDIT While i am working it still locks the computer even when the drive is connected, so something is not going correct. Edited November 20, 2018 by Iznogoud
ModemJunki Posted November 20, 2018 Posted November 20, 2018 (edited) 20 minutes ago, Iznogoud said: While i am working it still locks the computer even when the drive is connected, so something is not going correct. Hmmm.... Again I will suggest to abandon devcon and use WMI instead. There must be a way for you to do this without the external program and it's overhead. When I look into "SELECT * FROM Win32_PnPEntity" I can for certain see a list of device IDs. AutoIt Scriptomatic is our friend! expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "ClassGuid: " & $objItem.ClassGuid & @CRLF $strCompatibleID = $objItem.CompatibleID(0) $Output = $Output & "CompatibleID: " & $strCompatibleID & @CRLF $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $strHardwareID = $objItem.HardwareID(0) $Output = $Output & "HardwareID: " & $strHardwareID & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "PNPClass: " & $objItem.PNPClass & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output = $Output & "Present: " & $objItem.Present & @CRLF $Output = $Output & "Service: " & $objItem.Service & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PnPEntity" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc And maybe some inspiration from here: Edited November 20, 2018 by ModemJunki Add USB drive monitor link Always carry a towel.
Iznogoud Posted November 20, 2018 Author Posted November 20, 2018 (edited) 19 minutes ago, ModemJunki said: Hmmm.... Again I will suggest to abandon devcon and use WMI instead. There must be a way for you to do this without the external program and it's overhead. When I look into "SELECT * FROM Win32_PnPEntity" I can for certain see a list of device IDs. AutoIt Scriptomatic is our friend! expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "ClassGuid: " & $objItem.ClassGuid & @CRLF $strCompatibleID = $objItem.CompatibleID(0) $Output = $Output & "CompatibleID: " & $strCompatibleID & @CRLF $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $strHardwareID = $objItem.HardwareID(0) $Output = $Output & "HardwareID: " & $strHardwareID & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "PNPClass: " & $objItem.PNPClass & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output = $Output & "Present: " & $objItem.Present & @CRLF $Output = $Output & "Service: " & $objItem.Service & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PnPEntity" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc And maybe some inspiration from here: This looks really good, but way to difficult for my skill level.... I tried the USB Drive Monitor script, but that gives me an error also: ==> Variable must be of type "Object".: $colEvents = $objWMIService.ExecNotificationQuery ("Select * From __InstanceOperationEvent Within 5 Where " & "TargetInstance isa 'Win32_LogicalDisk'") $colEvents = $objWMIService^ ERROR >Exit code: 1 Time: 0.3105 Edited November 20, 2018 by Iznogoud
ModemJunki Posted November 20, 2018 Posted November 20, 2018 I'm bored. Surely there must be a better way than my code, but - it seems to work. Just change the "$s_DeviceID" to yours... can be partial string or full path. expandcollapse popup#include <winapi.au3> #include <array.au3> ;~ #include <debug.au3> ;~ $s_DeviceID = "VID_0781&PID_5530" ; can be partial string $s_DeviceID = "USB\VID_0781&PID_5530\20052443900EBFD165D2" ; can be full path of string _MainFunc($s_DeviceID, 3000) Func _MainFunc($s_ID, $s_Delay) $i = 1 Do If _ArrayFindAll(_GetPnPEntity($s_ID), $s_ID) Then ConsoleWrite("Found device!" & @CRLF) ContinueLoop 1 Else ConsoleWrite("No device found." & @CRLF) _WinAPI_LockWorkStation() ContinueLoop 1 EndIf Sleep($s_Delay) Until $i = 0 EndFunc ;==>_MainFunc ;~ ; You can play with the below to see all the datas retrieved from the PnPEntity WMI query ;~ $a_PnP = _GetPnPEntity($s_DeviceID) ;~ _ArraySort($a_PnP, "", "", "", 1) ;~ _ArrayDisplay($a_PnP, "PnPEntity", "", "", "", "Availability|Caption|ClassGuid|CompatibleID|ConfigManagerErrorCode|ConfigManagerUserConfig|CreationClassName|Description|DeviceID|ErrorCleared|ErrorDescription|HardwareID|InstallDate|LastErrorCode|Manufacturer|Name|PNPClass|PNPDeviceID|PowerManagementCapabilities|PowerManagementSupported|Present|Service|Status|StatusInfo|SystemCreationClassName|SystemName") ;~ _DebugArrayDisplay($a_PnP, "PnPEntity", "", "", "", "Availability|Caption|ClassGuid|CompatibleID|ConfigManagerErrorCode|ConfigManagerUserConfig|CreationClassName|Description|DeviceID|ErrorCleared|ErrorDescription|HardwareID|InstallDate|LastErrorCode|Manufacturer|Name|PNPClass|PNPDeviceID|PowerManagementCapabilities|PowerManagementSupported|Present|Service|Status|StatusInfo|SystemCreationClassName|SystemName") Func _GetPnPEntity($s_DeviceID = "") If StringInStr($s_DeviceID, "\") Then $s_DeviceID = StringReplace($s_DeviceID, "\", "\\") Local $colItems, $objWMIService, $objItem Local $strComputer = "localhost" Dim $aPnPEntity[1][26], $i = 1 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") If $s_DeviceID = "" Then Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL") ; , 0x10 + 0x20) Else Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%" & $s_DeviceID & "%'", "WQL") ; , 0x10 + 0x20) EndIf If IsObj($colItems) Then For $objItem In $colItems ReDim $aPnPEntity[UBound($aPnPEntity) + 1][26] $aPnPEntity[$i][0] = $objItem.Availability & @CRLF $aPnPEntity[$i][1] = $objItem.Caption & @CRLF $aPnPEntity[$i][2] = $objItem.ClassGuid & @CRLF Local $strCompatibleID = $objItem.CompatibleID(0) $aPnPEntity[$i][3] = $strCompatibleID & @CRLF $aPnPEntity[$i][4] = $objItem.ConfigManagerErrorCode & @CRLF $aPnPEntity[$i][5] = $objItem.ConfigManagerUserConfig & @CRLF $aPnPEntity[$i][6] = $objItem.CreationClassName & @CRLF $aPnPEntity[$i][7] = $objItem.Description & @CRLF $aPnPEntity[$i][8] = $objItem.DeviceID & @CRLF $aPnPEntity[$i][9] = $objItem.ErrorCleared & @CRLF $aPnPEntity[$i][10] = $objItem.ErrorDescription & @CRLF Local $strHardwareID = $objItem.HardwareID(0) $aPnPEntity[$i][11] = $strHardwareID & @CRLF $aPnPEntity[$i][12] = WMIDateStringToDate($objItem.InstallDate) & @CRLF $aPnPEntity[$i][13] = $objItem.LastErrorCode & @CRLF $aPnPEntity[$i][14] = $objItem.Manufacturer & @CRLF $aPnPEntity[$i][15] = $objItem.Name & @CRLF $aPnPEntity[$i][16] = $objItem.PNPClass & @CRLF $aPnPEntity[$i][17] = $objItem.PNPDeviceID & @CRLF Local $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $aPnPEntity[$i][18] = $strPowerManagementCapabilities & @CRLF $aPnPEntity[$i][19] = $objItem.PowerManagementSupported & @CRLF $aPnPEntity[$i][20] = $objItem.Present & @CRLF $aPnPEntity[$i][21] = $objItem.Service & @CRLF $aPnPEntity[$i][22] = $objItem.Status & @CRLF $aPnPEntity[$i][23] = $objItem.StatusInfo & @CRLF $aPnPEntity[$i][24] = $objItem.SystemCreationClassName & @CRLF $aPnPEntity[$i][25] = $objItem.SystemName & @CRLF $i += 1 Next $aPnPEntity[0][0] = UBound($aPnPEntity) - 1 If $aPnPEntity[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf Return $aPnPEntity EndFunc ;==>_GetPnPEntity Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2)) EndFunc ;==>WMIDateStringToDate Always carry a towel.
Iznogoud Posted November 20, 2018 Author Posted November 20, 2018 2 hours ago, ModemJunki said: I'm bored. Surely there must be a better way than my code, but - it seems to work. Just change the "$s_DeviceID" to yours... can be partial string or full path. expandcollapse popup#include <winapi.au3> #include <array.au3> ;~ #include <debug.au3> ;~ $s_DeviceID = "VID_0781&PID_5530" ; can be partial string $s_DeviceID = "USB\VID_0781&PID_5530\20052443900EBFD165D2" ; can be full path of string _MainFunc($s_DeviceID, 3000) Func _MainFunc($s_ID, $s_Delay) $i = 1 Do If _ArrayFindAll(_GetPnPEntity($s_ID), $s_ID) Then ConsoleWrite("Found device!" & @CRLF) ContinueLoop 1 Else ConsoleWrite("No device found." & @CRLF) _WinAPI_LockWorkStation() ContinueLoop 1 EndIf Sleep($s_Delay) Until $i = 0 EndFunc ;==>_MainFunc ;~ ; You can play with the below to see all the datas retrieved from the PnPEntity WMI query ;~ $a_PnP = _GetPnPEntity($s_DeviceID) ;~ _ArraySort($a_PnP, "", "", "", 1) ;~ _ArrayDisplay($a_PnP, "PnPEntity", "", "", "", "Availability|Caption|ClassGuid|CompatibleID|ConfigManagerErrorCode|ConfigManagerUserConfig|CreationClassName|Description|DeviceID|ErrorCleared|ErrorDescription|HardwareID|InstallDate|LastErrorCode|Manufacturer|Name|PNPClass|PNPDeviceID|PowerManagementCapabilities|PowerManagementSupported|Present|Service|Status|StatusInfo|SystemCreationClassName|SystemName") ;~ _DebugArrayDisplay($a_PnP, "PnPEntity", "", "", "", "Availability|Caption|ClassGuid|CompatibleID|ConfigManagerErrorCode|ConfigManagerUserConfig|CreationClassName|Description|DeviceID|ErrorCleared|ErrorDescription|HardwareID|InstallDate|LastErrorCode|Manufacturer|Name|PNPClass|PNPDeviceID|PowerManagementCapabilities|PowerManagementSupported|Present|Service|Status|StatusInfo|SystemCreationClassName|SystemName") Func _GetPnPEntity($s_DeviceID = "") If StringInStr($s_DeviceID, "\") Then $s_DeviceID = StringReplace($s_DeviceID, "\", "\\") Local $colItems, $objWMIService, $objItem Local $strComputer = "localhost" Dim $aPnPEntity[1][26], $i = 1 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") If $s_DeviceID = "" Then Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL") ; , 0x10 + 0x20) Else Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%" & $s_DeviceID & "%'", "WQL") ; , 0x10 + 0x20) EndIf If IsObj($colItems) Then For $objItem In $colItems ReDim $aPnPEntity[UBound($aPnPEntity) + 1][26] $aPnPEntity[$i][0] = $objItem.Availability & @CRLF $aPnPEntity[$i][1] = $objItem.Caption & @CRLF $aPnPEntity[$i][2] = $objItem.ClassGuid & @CRLF Local $strCompatibleID = $objItem.CompatibleID(0) $aPnPEntity[$i][3] = $strCompatibleID & @CRLF $aPnPEntity[$i][4] = $objItem.ConfigManagerErrorCode & @CRLF $aPnPEntity[$i][5] = $objItem.ConfigManagerUserConfig & @CRLF $aPnPEntity[$i][6] = $objItem.CreationClassName & @CRLF $aPnPEntity[$i][7] = $objItem.Description & @CRLF $aPnPEntity[$i][8] = $objItem.DeviceID & @CRLF $aPnPEntity[$i][9] = $objItem.ErrorCleared & @CRLF $aPnPEntity[$i][10] = $objItem.ErrorDescription & @CRLF Local $strHardwareID = $objItem.HardwareID(0) $aPnPEntity[$i][11] = $strHardwareID & @CRLF $aPnPEntity[$i][12] = WMIDateStringToDate($objItem.InstallDate) & @CRLF $aPnPEntity[$i][13] = $objItem.LastErrorCode & @CRLF $aPnPEntity[$i][14] = $objItem.Manufacturer & @CRLF $aPnPEntity[$i][15] = $objItem.Name & @CRLF $aPnPEntity[$i][16] = $objItem.PNPClass & @CRLF $aPnPEntity[$i][17] = $objItem.PNPDeviceID & @CRLF Local $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $aPnPEntity[$i][18] = $strPowerManagementCapabilities & @CRLF $aPnPEntity[$i][19] = $objItem.PowerManagementSupported & @CRLF $aPnPEntity[$i][20] = $objItem.Present & @CRLF $aPnPEntity[$i][21] = $objItem.Service & @CRLF $aPnPEntity[$i][22] = $objItem.Status & @CRLF $aPnPEntity[$i][23] = $objItem.StatusInfo & @CRLF $aPnPEntity[$i][24] = $objItem.SystemCreationClassName & @CRLF $aPnPEntity[$i][25] = $objItem.SystemName & @CRLF $i += 1 Next $aPnPEntity[0][0] = UBound($aPnPEntity) - 1 If $aPnPEntity[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf Return $aPnPEntity EndFunc ;==>_GetPnPEntity Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2)) EndFunc ;==>WMIDateStringToDate You are great!!! thank you for you time and effort!! None the less i have a problem, when i use the Hardware ID it says device not found, so i think your script is using an other kind of ID. How can i check if it uses the right ID of my yubikey?
ModemJunki Posted November 21, 2018 Posted November 21, 2018 46 minutes ago, Iznogoud said: You are great!!! thank you for you time and effort!! None the less i have a problem, when i use the Hardware ID it says device not found, so i think your script is using an other kind of ID. How can i check if it uses the right ID of my yubikey? You are welcome. Can you try with only "VID_1050&PID_0114" as the device string? Otherwise you can use the _GetPnPEntity function with the parts I commented out as it's own script to get all of the PnP entities in a table you can look at. Like so: expandcollapse popup#include <winapi.au3> #include <array.au3> #include <debug.au3> ;~ ; You can play with the below to see all the datas retrieved from the PnPEntity WMI query $a_PnP = _GetPnPEntity() _ArraySort($a_PnP, "", "", "", 1) _DebugArrayDisplay($a_PnP, "PnPEntity", "", "", "", "Availability|Caption|ClassGuid|CompatibleID|ConfigManagerErrorCode|ConfigManagerUserConfig|CreationClassName|Description|DeviceID|ErrorCleared|ErrorDescription|HardwareID|InstallDate|LastErrorCode|Manufacturer|Name|PNPClass|PNPDeviceID|PowerManagementCapabilities|PowerManagementSupported|Present|Service|Status|StatusInfo|SystemCreationClassName|SystemName") Func _GetPnPEntity($s_DeviceID = "") If StringInStr($s_DeviceID, "\") Then $s_DeviceID = StringReplace($s_DeviceID, "\", "\\") Local $colItems, $objWMIService, $objItem Local $strComputer = "localhost" Dim $aPnPEntity[1][26], $i = 1 Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") If $s_DeviceID = "" Then Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity", "WQL") ; , 0x10 + 0x20) Else Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE '%" & $s_DeviceID & "%'", "WQL") ; , 0x10 + 0x20) EndIf If IsObj($colItems) Then For $objItem In $colItems ReDim $aPnPEntity[UBound($aPnPEntity) + 1][26] $aPnPEntity[$i][0] = $objItem.Availability & @CRLF $aPnPEntity[$i][1] = $objItem.Caption & @CRLF $aPnPEntity[$i][2] = $objItem.ClassGuid & @CRLF Local $strCompatibleID = $objItem.CompatibleID(0) $aPnPEntity[$i][3] = $strCompatibleID & @CRLF $aPnPEntity[$i][4] = $objItem.ConfigManagerErrorCode & @CRLF $aPnPEntity[$i][5] = $objItem.ConfigManagerUserConfig & @CRLF $aPnPEntity[$i][6] = $objItem.CreationClassName & @CRLF $aPnPEntity[$i][7] = $objItem.Description & @CRLF $aPnPEntity[$i][8] = $objItem.DeviceID & @CRLF $aPnPEntity[$i][9] = $objItem.ErrorCleared & @CRLF $aPnPEntity[$i][10] = $objItem.ErrorDescription & @CRLF Local $strHardwareID = $objItem.HardwareID(0) $aPnPEntity[$i][11] = $strHardwareID & @CRLF $aPnPEntity[$i][12] = WMIDateStringToDate($objItem.InstallDate) & @CRLF $aPnPEntity[$i][13] = $objItem.LastErrorCode & @CRLF $aPnPEntity[$i][14] = $objItem.Manufacturer & @CRLF $aPnPEntity[$i][15] = $objItem.Name & @CRLF $aPnPEntity[$i][16] = $objItem.PNPClass & @CRLF $aPnPEntity[$i][17] = $objItem.PNPDeviceID & @CRLF Local $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $aPnPEntity[$i][18] = $strPowerManagementCapabilities & @CRLF $aPnPEntity[$i][19] = $objItem.PowerManagementSupported & @CRLF $aPnPEntity[$i][20] = $objItem.Present & @CRLF $aPnPEntity[$i][21] = $objItem.Service & @CRLF $aPnPEntity[$i][22] = $objItem.Status & @CRLF $aPnPEntity[$i][23] = $objItem.StatusInfo & @CRLF $aPnPEntity[$i][24] = $objItem.SystemCreationClassName & @CRLF $aPnPEntity[$i][25] = $objItem.SystemName & @CRLF $i += 1 Next $aPnPEntity[0][0] = UBound($aPnPEntity) - 1 If $aPnPEntity[0][0] < 1 Then SetError(1, 1, 0) EndIf Else SetError(1, 2, 0) EndIf Return $aPnPEntity EndFunc ;==>_GetPnPEntity Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate, 13, 2)) EndFunc ;==>WMIDateStringToDate Produces output like in the attached image file, but since I put the script with _DebugArrayDisplay, you can highlight the device and click the "copy data" button (it copies all the entries so paste into Notepad or a new file in SciTE and grab the ID you need from there). Always carry a towel.
Iznogoud Posted January 9, 2019 Author Posted January 9, 2019 Hi, Sorry for my late response, but i want to say your script works great and fast! Really good addition for my own security. But i do have one question, it now checks for 1 hardware ID, is it possible to add additional Hardware ID's ? For an example a back-up yubikey? I tried adding additional functions and renaming them, but i think i am creating a bigger mess then needed. Do you have suggestions?
Nine Posted January 9, 2019 Posted January 9, 2019 (edited) Something like it would work (untested). Replace your main func with this along with the device id. Rest should stay as is... $s_DeviceID [3] = ["VID_0781&PID_5530","Device #2","Device #3"] _MainFunc($s_DeviceID, 3000) Func _MainFunc($s_ID, $s_Delay) While True For $i = 0 to Ubound($s_ID)-1 If not _ArrayFindAll(_GetPnPEntity($s_ID[$i]), $s_ID[$i]) Then ConsoleWrite("At least one device not found." & @CRLF) _WinAPI_LockWorkStation() Exit endif Next ConsoleWrite("Found all devices! Sleep for awhile now" & @CRLF) Sleep($s_Delay) Wend EndFunc ;==>_MainFunc I made it for 3 devices but you can extend it as you wish... Edited January 9, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Iznogoud Posted February 6, 2019 Author Posted February 6, 2019 @Nine Sorry for my late reply, some issues i will not bother you with. But for some reason there is an error with this line $s_DeviceID [3] = ["VID_0781&PID_5530","Device #2","Device #3"] I can't get rid off it unless i use one DeviceID, but i was wondering, and trying now with one DeviceID, is it possible to secure a specific application with this script? What i would like to accomplish is an executable which a user can start and then it shows a GUI with a list of buttons with every single name of the employees, when clicked on User1 it then checks if the correct DeviceID is present, if so it should start the application, otherwise it should close / stop the entire script. When the DeviceID is unplugged from the system, it should close the application. This can be done with a simple processkill. Is this possible?
Nine Posted February 6, 2019 Posted February 6, 2019 (edited) 5 hours ago, Iznogoud said: What i would like to accomplish is an executable which a user can start and then it shows a GUI with a list of buttons with every single name of the employees, when clicked on User1 it then checks if the correct DeviceID is present, if so it should start the application, otherwise it should close / stop the entire script. When the DeviceID is unplugged from the system, it should close the application. This can be done with a simple processkill. Is this possible? Yes it is totally possible. But instead of using buttons for employees, I would use a drop-down list or something similar since the number of employees can vary in time. You must have a list somewhere that you can read and feed the drop-down list. Just start Scite and go into Koda tool to design your GUI. Basic code will be generated and you can add the above script once you are satisfied with the interface. Happy Scripting ! Edited February 6, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Iznogoud Posted February 7, 2019 Author Posted February 7, 2019 On 6-2-2019 at 2:03 PM, Nine said: Yes it is totally possible. But instead of using buttons for employees, I would use a drop-down list or something similar since the number of employees can vary in time. You must have a list somewhere that you can read and feed the drop-down list. Just start Scite and go into Koda tool to design your GUI. Basic code will be generated and you can add the above script once you are satisfied with the interface. Happy Scripting ! Hi, i don't want to be bold, but can't you help me with this? I am even willing to pay for the services, because you probably can get this done alot quicker then i would. I don't mind to change the GUI with buttons time to time, so buttons are quicker for the employees.
Nine Posted February 7, 2019 Posted February 7, 2019 (edited) Sorry I don't take contract. I am retired and have no intention of going back to all that stuff relating to job. But there is some ppl here that are very very good. Maybe you could message them. Or they will since you offering... Edit. But really I am kind of flattered of your offer... Edited February 7, 2019 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
spudw2k Posted February 8, 2019 Posted February 8, 2019 On 2/6/2019 at 4:36 PM, Iznogoud said: But for some reason there is an error with this line $s_DeviceID [3] = ["VID_0781&PID_5530","Device #2","Device #3"] You need to "instantiate" the array by putting either local or global in front of it as appropriate. Local $s_DeviceID [3] = ["VID_0781&PID_5530","Device #2","Device #3"] Look in the help file under the Keyword Reference at the Dim article if you are not familiar with variable scopes (global vs local). Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Iznogoud Posted February 13, 2019 Author Posted February 13, 2019 I tried contacting some people on the forum which offered their services before, but i still got no response. Could someone help me with the last step the put a GUI in front of it with buttons and when User Y is selected it will try to detect the hardware ID and will loop itself like it does now. When the hardware ID is disconnected it needs to close the application instead of logging off.
FrancescoDiMuro Posted February 13, 2019 Posted February 13, 2019 (edited) Snip. Edited February 13, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
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