Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/05/2022 in all areas

  1. kaz

    GDI+ clock

    Another GDI+ clock with google watch look. i hope you'll like it. Some code should look familiar for someone. Sorry if code isn't clean. GDI+_Clock.au3
    2 points
  2. Back when the issue regarding not being able to access keys that have periods in them was posted HERE on 9/18, I took a look at the issue and fixed my local copy. Then, I saw the post HERE on 9/28 that had the same issue. After mulling it over a bit, I decided to share my fix (attached below). Even though there are other JSON UDF's available that do not have this issue, I decided that it was still important to offer a fix since this UDF lib is widely used and very fast when doing simple parsing. Of course one can access keys with periods in them by directly accessing the underlying dictionary, where the key/value pairs are actually stored. However, that doesn't address being able to access & manipulate such keys, using dot-notation and bracket-notation, with the Json_Get() and Json_Put() functions. Only 4 lines in the most current version needed to be modified, 2 lines in Json_Get() and 2 lines in Json_Put(). I could go into a detailed analysis of the root cause(s) of the issue and why I chose to fix it the way I did, but I'm sure that most don't care. All anyone really cares about is that it works. 😉 I left the Json_ObjGet() and Json_ObjExists() helper functions as-is. Although those 2 helper functions are related to the issue, they are not needed for Json_Get() and Json_Put() to correctly traverse a mutli-level JSON notation that has special characters like slashes, spaces, brackets, and periods. The example script below shows keys with periods, spaces, brackets, and slashes, being created, accessed, and modified, using Json_Put() and Json_Get(): #include <Constants.au3> ;~ #include "Json.au3" #include "Json(2022-09-18)_TheXman.au3" ;<== Modified json.au3 (only 4 lines updated) Const $JSON = _ '{' & _ ' "dual_engine": {' & _ ' "user_list_data_1": {' & _ ' "https://www.yahoo.com/": {' & _ ' "date_added": "13308840098237395",' & _ ' "engine": 2,' & _ ' "visits_after_expiration": 0' & _ ' }' & _ ' }' & _ ' },' & _ ' "VST.magic": "Test",' & _ ' "VST3.uid": [2229853791, 2455052834, 2533024787],' & _ ' "pluginName": "Omnisphere",' & _ ' "pluginVendor": "Spectrasonics"' & _ '}' json_example() Func json_example() Local $oJson ;Decode JSON into a dictionary object $oJson = Json_Decode($JSON) If @error Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "JSON DECODE ERROR", "@error = " & @error) ;Pretty-print the original JSON log_line("=== Pretty-Printed JSON (original) ===") log_line(Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_SLASHES, " ") & @CRLF) ;Update an existing key / Add some valid keys with spaces, slashes, and periods Json_Put($oJson, '.dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration', 3) ;Update key's value to 3 Json_Put($oJson, '."//a.b.c//".". [.] ."', "Value of ridiculous but valid key (. [.] .)") ;Add key Json_Put($oJson, '."//a.b.c//"."/ /"' , "Value of another ridiculous but valid key (/ /)") ;Add key Json_Put($oJson, '."key with spaces"' , "Value of key with spaces") ;Add key Json_Put($oJson, '."lvl1.key"."lvl2.key1"."lvl3.key1"' , "Level 3 Key1") ;Add key using dot-notation Json_Put($oJson, '["lvl1.key"]["lvl2.key1"]["lvl3.key2"]', "Level 3 Key2") ;Add key using bracket-notation ;Pretty-print the updated JSON log_line("=== Pretty-Printed JSON (with keys updated/added) ===") log_line(Json_Encode($oJson, $JSON_PRETTY_PRINT + $JSON_UNESCAPED_SLASHES, " ") & @CRLF) ;Display some of the JSON values log_line('=== Display some JSON keys & values ===') log_line('."//a.b.c//".". [.] ." => ' & Json_Get($oJson, '."//a.b.c//".". [.] ."')) log_line('."//a.b.c//"."/ /" => ' & Json_Get($oJson, '."//a.b.c//"."/ /"')) log_line('."key with spaces" => ' & Json_Get($oJson, '."key with spaces"')) log_line() log_line('.dual_engine.user_list_data_1."https://www.yahoo.com/".date_added => ' & _ Json_Get($oJson, '.dual_engine.user_list_data_1."https://www.yahoo.com/".date_added')) log_line('[dual_engine][user_list_data_1]["https://www.yahoo.com/"][engine] => ' & _ Json_Get($oJson, '[dual_engine][user_list_data_1]["https://www.yahoo.com/"][engine]')) log_line('.dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration => ' & _ Json_Get($oJson, '.dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration')) log_line() log_line('."VST.magic" => ' & Json_Get($oJson, '."VST.magic"')) log_line('."VST3.uid"[0] => ' & Json_Get($oJson, '."VST3.uid"[0]')) log_line() log_line('."lvl1.key"."lvl2.key1"."lvl3.key1" => ' & Json_Get($oJson, '."lvl1.key"."lvl2.key1"."lvl3.key1"')) log_line('["lvl1.key"]["lvl2.key1"]["lvl3.key1"] => ' & Json_Get($oJson, '["lvl1.key"]["lvl2.key1"]["lvl3.key1"]')) EndFunc Func log_line($sMsg = "") ConsoleWrite($sMsg & @CRLF) EndFunc Console Output: === Pretty-Printed JSON (original) === { "dual_engine": { "user_list_data_1": { "https://www.yahoo.com/": { "date_added": "13308840098237395", "engine": 2, "visits_after_expiration": 0 } } }, "VST.magic": "Test", "VST3.uid": [ 2229853791, 2455052834, 2533024787 ], "pluginName": "Omnisphere", "pluginVendor": "Spectrasonics" } === Pretty-Printed JSON (with keys updated/added) === { "VST.magic": "Test", "VST3.uid": [ 2229853791, 2455052834, 2533024787 ], "pluginName": "Omnisphere", "pluginVendor": "Spectrasonics", "dual_engine": { "user_list_data_1": { "https://www.yahoo.com/": { "date_added": "13308840098237395", "engine": 2, "visits_after_expiration": 3 } } }, "//a.b.c//": { ". [.] .": "Value of ridiculous but valid key (. [.] .)", "/ /": "Value of another ridiculous but valid key (/ /)" }, "key with spaces": "Value of key with spaces", "lvl1.key": { "lvl2.key1": { "lvl3.key1": "Level 3 Key1", "lvl3.key2": "Level 3 Key2" } } } === Display some JSON keys & values === ."//a.b.c//".". [.] ." => Value of ridiculous but valid key (. [.] .) ."//a.b.c//"."/ /" => Value of another ridiculous but valid key (/ /) ."key with spaces" => Value of key with spaces .dual_engine.user_list_data_1."https://www.yahoo.com/".date_added => 13308840098237395 [dual_engine][user_list_data_1]["https://www.yahoo.com/"][engine] => 2 .dual_engine.user_list_data_1."https://www.yahoo.com/".visits_after_expiration => 3 ."VST.magic" => Test ."VST3.uid"[0] => 2229853791 ."lvl1.key"."lvl2.key1"."lvl3.key1" => Level 3 Key1 ["lvl1.key"]["lvl2.key1"]["lvl3.key1"] => Level 3 Key1 Json(2022-09-18)_TheXman.au3
    1 point
  3. See if this will help. May need some tweaking. Global $objWMIService, $strIPAddress , $wbemFlagReturnImmediately, $wbemFlagForwardOnly, $NetConnectionID, $Index Global $strComputer = @ComputerName $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2") If $objWMIService = 0 Then MsgBox(0, "WMI Error", "Please Fix WMI") ElseIf $objWMIService <> 0 Then _GetIndex() EndIf Func _GetIndex() ;Gets Index Address based on IPAddress $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE', "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $strIPAddress = $objItem.IPAddress(0) $IpAddressLen = StringLeft($strIPAddress, 3) If $IpAddressLen = "192" Then $strIndex = $objItem.Index If StringLen($strIndex) = 1 Then $Index = "000" & $strIndex If StringLen($strIndex) = 2 Then $Index = "00" & $strIndex _NetConnectionID() MsgBox(0, "Network Name", $NetConnectionID) EndIf Next EndIf EndFunc ;==>_GetIndex Func _NetConnectionID() ;Gets NetConnectionID, ie 'Local Area Connection' $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter where Index=" & $Index, "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems $NetConnectionID = $objItem.NetConnectionID Next Else EndIf EndFunc ;==>_NetConnectionID
    1 point
  4. @erebus This will list all your adapters : ; 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_NetworkAdapter", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "AdapterType: " & $objItem.AdapterType & @CRLF $Output = $Output & "AdapterTypeId: " & $objItem.AdapterTypeId & @CRLF $Output = $Output & "AutoSense: " & $objItem.AutoSense & @CRLF $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @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 $Output = $Output & "Index: " & $objItem.Index & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "Installed: " & $objItem.Installed & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "MACAddress: " & $objItem.MACAddress & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "MaxNumberControlled: " & $objItem.MaxNumberControlled & @CRLF $Output = $Output & "MaxSpeed: " & $objItem.MaxSpeed & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "NetConnectionID: " & $objItem.NetConnectionID & @CRLF $Output = $Output & "NetConnectionStatus: " & $objItem.NetConnectionStatus & @CRLF $strNetworkAddresses = $objItem.NetworkAddresses(0) $Output = $Output & "NetworkAddresses: " & $strNetworkAddresses & @CRLF $Output = $Output & "PermanentAddress: " & $objItem.PermanentAddress & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output = $Output & "ProductName: " & $objItem.ProductName & @CRLF $Output = $Output & "ServiceName: " & $objItem.ServiceName & @CRLF $Output = $Output & "Speed: " & $objItem.Speed & @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 $Output = $Output & "TimeOfLastReset: " & WMIDateStringToDate($objItem.TimeOfLastReset) & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapter" ) 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 this will show all information about the adaptors. And if I remember well check the output called "NetConnectionStatus" = 2 regards ptrex
    1 point
×
×
  • Create New...