Leaderboard
Popular Content
Showing content with the highest reputation on 08/08/2024 in all areas
-
I started here to get a list of networks. MS information can be found here.2 points
-
I use the following script to check that the computer is connected to an AD domain: ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name ..........: __NetworkCheck ; Description ...: Check if the local machine is connected to a domain. ; Syntax ........: __NetworkCheck() ; Parameters ....: None ; Return values .: Success - One of the following integer values: ; |0 - The local machine is not connected to a domain ; |1 - The local machine is connected to a domain ; Failure - 0 and sets @error to one of the following values: ; |1 = Could not create the NLM object ; |2 = Could not create the NetworkConnections object ; |3 = Could not create the Network object ; Author ........: water ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: https://learn.microsoft.com/en-us/windows/win32/NLA/portal ; https://www.autoitscript.com/forum/topic/174245-get-connected-networks/?do=findComment&comment=1261045 ; Example .......: ; =============================================================================================================================== Func __NetworkCheck() ; NLM_DOMAIN_TYPE: The NLM_DOMAIN_TYPE enumeration is a set of flags that specify the domain type of a network. ; See: https://learn.microsoft.com/en-us/windows/win32/api/netlistmgr/ne-netlistmgr-nlm_domain_type Local Const $NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK = 0 Local Const $NLM_DOMAIN_TYPE_DOMAIN_NETWORK = 0x1 Local Const $NLM_DOMAIN_TYPE_DOMAIN_AUTHENTICATED = 0x2 #forceref $NLM_DOMAIN_TYPE_NON_DOMAIN_NETWORK Local $bConnected2Domain = False Local $sNLM_ClsID = "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}" Local $oNLM, $oNetworkConnections, $oNetwork $oNLM = ObjCreate($sNLM_ClsID) ; Create the object for the Network List Manager If @error Then Return SetError(1, @error, 0) If $oNLM.IsConnected Then ; The local machine has network connectivity, check details $oNetworkConnections = $oNLM.GetNetworkConnections ; Get the collection of NetworkConnections If @error Then Return SetError(2, @error, 0) For $oNetworkConnection In $oNetworkConnections ; Check each NetworkConnection $oNetwork = $oNetworkConnection.GetNetwork If @error Then Return SetError(3, @error, 0) If $oNetwork.IsConnected = True And ($oNetwork.GetDomainType = $NLM_DOMAIN_TYPE_DOMAIN_NETWORK Or $oNetwork.GetDomainType = $NLM_DOMAIN_TYPE_DOMAIN_AUTHENTICATED) Then $bConnected2Domain = True Next Return ($bConnected2Domain = True) ? 1 : 0 Else Return 0 EndIf EndFunc ;==>__NetworkCheck1 point
-
Detecting USB device connects & disconnects and log them to a file
argumentum reacted to konya for a topic
This reply may be ten years late but I hope it will be helpful to future learners. How to use : 1.Run this code 2.Plugin or Unplug usb device 3.It is will pop-up message #include <WinAPI.au3> #include <Array.au3> #include <WinAPIDiag.au3> HotKeySet("{ESC}", "_exit") Global Const $WM_DEVICECHANGE = 537 Global Const $DBT_CONFIGCHANGECANCELED = 0x0019 Global Const $DBT_CONFIGCHANGED = 0x0018 Global Const $DBT_CUSTOMEVENT = 0x8006 Global Const $DBT_DEVICEARRIVAL = 0x8000 Global Const $DBT_DEVICEQUERYREMOVE = 0x8001 Global Const $DBT_DEVICEQUERYREMOVEFAILED = 0x8002 Global Const $DBT_DEVICEREMOVEPENDING = 0x8003 Global Const $DBT_DEVICEREMOVECOMPLETE = 0x8004 Global Const $DBT_DEVICETYPESPECIFIC = 0x8005 Global Const $DBT_DEVNODES_CHANGED = 0x0007 Global Const $DBT_QUERYCHANGECONFIG = 0x0017 Global Const $DBT_USERDEFINED = 0xFFFF Global Const $DBT_DEVTYP_OEM = 0x00000000 Global Const $DBT_DEVTYP_DEVNODE = 0x00000001 Global Const $DBT_DEVTYP_VOLUME = 0x00000002 Global Const $DBT_DEVTYP_PORT = 0x00000003 Global Const $DBT_DEVTYP_NET = 0x00000004 Global Const $DBT_DEVTYP_DEVICEINTERFACE = 0x00000005 Global Const $DBT_DEVTYP_HANDLE = 0x00000006 Global Const $DBT_DEVTYP_DEVINST = 0x00000007 Global Const $DEVICE_NOTIFY_WINDOW_HANDLE = 0x00000000 Global Const $DEVICE_NOTIFY_SERVICE_HANDLE = 0x00000001 Global Const $DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 0x00000004 Global $RegisterDeviceInterface_Handle[0][2] Global $GUI_hwnd = GUICreate("Detect device change") Global Const $tagPack = "align 1;" Global Const $tagDEV_BROADCAST_HDR = _ "dword size;" & _ "dword devicetype;" & _ "dword reserved;" Global $DEV_BROADCAST_HDR = DllStructCreate($tagDEV_BROADCAST_HDR) Global Const $tagDEV_BROADCAST_USERDEFINED = _ $tagDEV_BROADCAST_HDR & _ "char szName[1];" Global $DEV_BROADCAST_USERDEFINED = DllStructCreate($tagDEV_BROADCAST_USERDEFINED) Global Const $tagDEV_BROADCAST_HANDLE = _ $tagDEV_BROADCAST_HDR & _ "handle handle;" & _ "ptr hdevnotify;" & _ $tagGUID & ";" & _ "long nameoffset;" & _ "byte data[1];" Global $DEV_BROADCAST_HANDLE = DllStructCreate($tagDEV_BROADCAST_HANDLE) Global Const $tagDEV_BROADCAST_DEVICEINTERFACE = _ $tagDEV_BROADCAST_HDR & _ $tagGUID & ";" & _ "WCHAR name[256];" Global $DEV_BROADCAST_DEVICEINTERFACE = DllStructCreate($tagDEV_BROADCAST_DEVICEINTERFACE) Global Const $tagDEV_BROADCAST_OEM = _ $tagDEV_BROADCAST_HDR & _ "dword identifier;" & _ "dword suppfunc" Global $DEV_BROADCAST_OEM = DllStructCreate($tagDEV_BROADCAST_OEM) Global Const $tagDEV_BROADCAST_PORT = _ $tagDEV_BROADCAST_HDR & _ "WCHAR name[256];" Global $DEV_BROADCAST_PORT = DllStructCreate($tagDEV_BROADCAST_PORT) Global Const $tagDEV_BROADCAST_VOLUME = _ $tagDEV_BROADCAST_HDR & _ "dword unitmask;" & _ "word flags;" Global $DEV_BROADCAST_VOLUME = DllStructCreate($tagDEV_BROADCAST_VOLUME) Local $Flags = $DEVICE_NOTIFY_WINDOW_HANDLE DoRegisterDeviceInterface($GUI_hwnd, "{A5DCBF10-6530-11D2-901F-00C04FB951ED}", $Flags) DoRegisterDeviceInterface($GUI_hwnd, "{f18a0e88-c30c-11d0-8815-00a0c906bed8}", $Flags) ;_ArrayDisplay($RegisterDeviceInterface_Handle) ;UnregisterDeviceNotification($RegisterDeviceInterface_Handle[1][1]) ;UnregisterDeviceNotification($RegisterDeviceInterface_Handle[0][1]) ;UnregisterDeviceNotification("{A5DCBF10-6530-11D2-901F-00C04FB951ED}") ;_ArrayDisplay($RegisterDeviceInterface_Handle) GUIRegisterMsg($WM_DEVICECHANGE, 'Detect_device') Do Until GUIGetMsg() = -3 Func Detect_device($hWnd, $Msg, $wParam, $lParam) Local $DEV_BROADCAST_GetDeviceType = DllStructCreate($tagDEV_BROADCAST_HDR, $lParam) Local $DeviceType = DllStructGetData($DEV_BROADCAST_GetDeviceType, "devicetype") Switch $wParam Case $DBT_DEVICEARRIVAL if $DeviceType = 5 Then $dddd = DllStructCreate($tagDEV_BROADCAST_DEVICEINTERFACE,$lParam) msgbox(0,"",'Detect device - ' & DEVTYP($DeviceType)&$dddd.name) ConsoleWrite('Detect device - ' & DEVTYP($DeviceType)&$dddd.name&@CRLF) EndIf Case $DBT_DEVICEQUERYREMOVE Case $DBT_DEVICEQUERYREMOVEFAILED Case $DBT_DEVICEREMOVEPENDING Case $DBT_DEVICEREMOVECOMPLETE if $DeviceType = 5 Then $dddd = DllStructCreate($tagDEV_BROADCAST_DEVICEINTERFACE,$lParam) msgbox(0,"",'Detect device remove - ' & DEVTYP($DeviceType)&$dddd.name) ConsoleWrite('Detect device remove - ' & DEVTYP($DeviceType)&$dddd.name&@CRLF) EndIf Case $DBT_DEVICETYPESPECIFIC Case $DBT_DEVNODES_CHANGED Case $DBT_CONFIGCHANGECANCELED Case $DBT_CONFIGCHANGED Case $DBT_CUSTOMEVENT Case $DBT_QUERYCHANGECONFIG Case $DBT_USERDEFINED EndSwitch Return 'GUI_RUNDEFMSG' EndFunc Func DEVTYP($lParam) Switch $lParam Case $DBT_DEVTYP_OEM Return "Type ( OEM ) " Case $DBT_DEVTYP_DEVNODE Return "Type ( DEVNODE ) " Case $DBT_DEVTYP_VOLUME Return "Type ( VOLUME ) " Case $DBT_DEVTYP_PORT Return "Type ( PORT ) " Case $DBT_DEVTYP_NET Return "Type ( NET ) " Case $DBT_DEVTYP_HANDLE Return "Type ( HANDLE ) " Case $DBT_DEVTYP_DEVICEINTERFACE Return "Type ( DEVICEINTERFACE ) " Case $DBT_DEVTYP_DEVINST Return "Type ( DEVINST ) " EndSwitch EndFunc Func DoRegisterDeviceInterface($hGUI, $Device_Class_GUID, $flags ) Local $ptrDEV_BROADCAST_DEVICEINTERFACE = DllStructGetPtr($DEV_BROADCAST_DEVICEINTERFACE) Local $Size = DllStructGetSize($DEV_BROADCAST_DEVICEINTERFACE) DllStructSetData($DEV_BROADCAST_DEVICEINTERFACE, "size", $Size) DllStructSetData($DEV_BROADCAST_DEVICEINTERFACE, "devicetype", $DBT_DEVTYP_DEVICEINTERFACE) Local $CameraGUID =_WinAPI_GUIDFromString($Device_Class_GUID) DllStructSetData($DEV_BROADCAST_DEVICEINTERFACE, "Data1", $CameraGUID.Data1) DllStructSetData($DEV_BROADCAST_DEVICEINTERFACE, "Data2", $CameraGUID.Data2) DllStructSetData($DEV_BROADCAST_DEVICEINTERFACE, "Data3", $CameraGUID.Data3) DllStructSetData($DEV_BROADCAST_DEVICEINTERFACE, "Data4", $CameraGUID.Data4) Local $RDNhandle = DllCall("User32.dll", "handle", "RegisterDeviceNotification", "hwnd", $hGUI, "ptr", $ptrDEV_BROADCAST_DEVICEINTERFACE, "long", $flags) _ArrayAdd($RegisterDeviceInterface_Handle, $RDNhandle[0]&"|"&StringUpper($Device_Class_GUID)) EndFunc Func UnregisterDeviceNotification($GUID) Local $delete_number = _ArraySearch($RegisterDeviceInterface_Handle,$GUID, 0, 0, 0, 0, 1, 2) Local $check = DllCall("User32.dll", "UINT", "UnregisterDeviceNotification", "handle", $RegisterDeviceInterface_Handle[$delete_number][0]) _ArrayDelete($RegisterDeviceInterface_Handle,$delete_number) EndFunc Func _exit() Exit EndFunc1 point -
Why AutoIt, and not another language like C# or Python?
CYCho reacted to lIlIIlIllIIIIlI for a topic
What I really dislike about python is how many files a simple program will write to disk, because of all the dependencies and libraries it's using which are also writing to disk. Running a python program, for example webtorrent cli, and checking later on with software for reading overwritten data, it is almost a thousand various python files that were deleted. That annoys me for some reason. When I run a program, I like when it's just a tool and it does something simple. But these python and javascript and other package managed languages that effortlessly summon a million other python programs and their dependencies and their specific versions... I can't fully explain why it annoys me but it just seems really sloppy and bad. There is beauty in a compiled program that doesn't rely on other things, but this view does not seem supported by python developers, I guess is a good way to put it. I also don't like how there is no end statements (or closing bracket equivalents for code depth) in python. It looks ugly in my opinion, visually unbalanced, and I rely on those end statements to parse stuff. Lua in my opinion is like a prettier version of python because of the end statements it has.1 point -
This QRCode UDF makes it possible to generate QRCodes and create an image or print it to the console. It provides functions to create a 2D-Boolean-Array of the QRCode, get a Bitmap (_GDIPlus) of that QRCode or to draw it directly at a GraphicsContext (_GDIPlus). To achieve this, I created a .dll in rust, which uses the "QR Code generator library (Rust)" by Project Nayuki (https://www.nayuki.io/page/qr-code-generator-library). Currently the following functions are included in the UDF: _QRCode_StartUp - Startup needed before using most other functions (Includes _GDIPlus_Startup) _QRCode_Shutdown - Shutdown should be called at the and to clean up (Includes _GDIPlus_Shutdown) _QRCode_GetQRCode - Generate a QRCode as 2D-Boolean-Array, where the first index = lines, the second index=cols, normally False=White, True=Black _QRCode_GetBitmap - Creates a GDIPlus-Bitmap with the QRCode _QRCode_DrawQRCode - Draws a QRCode on a provides GDIPlus-GraphicsContext _QRCode_DrawQRCodeFast - Same as _QRCode_DrawQRCode, but without error checks and requires brushes for the colors to be provided (=> higher FPS) _QRCode_ConsoleWrite - Print the QRCode to the console _QRCode_GetSize - Get the size of the generated QRCode _QRCode_GetECLMaxLoss - Get the maximum allowed loss before the qrcode becomes unreadable (decimal multiplier) Possible error correction levels: $_QRCode_ECL_LOW = 1 $_QRCode_ECL_MEDIUM = 2 $_QRCode_ECL_QUARTILE = 3 $_QRCode_ECL_HIGH = 4 - Default Here is an example, how the UDF could be used: Another example can be found with the QRCodeGenerator-cli: QRCode generator cli That is a console application with detailed possibilities for settings to generate qrcodes from the commandline. While developing in rust, I first created a .exe instead of the .dll. Calling the .exe and parsing the result was relatively slow (~1 sec), so I ditched that for the .dll. You can find the created .exe in the files as Rust-Executable (QRCode-Wrapper-Console-Rust-Exe.zip). It is a commandline utility to be called with a text with the corresponding qrcode being written to the console with 0 (white), 1 (black), 2 (new line). With --human the qrcode will be printed humanreadable and with --errorlvl low/medium/quartile/high, the error correction level can be provided. But this appilcation is inferior to the QRCodeGenerator-cli mentioned above and is just included for completeness. Files: The QRCode UDF with all needed files: qrcode.zip The Rust-Sourcecode of the .dll and .exe: QRCode-Dll-Exe-Rust-Src.zip The Rust-Executable: QRCode-Wrapper-Console-Rust.zip QRCode-Wrapper-Console-Rust-Exe.zip qrcode.zip QRCode-Dll-Exe-Rust-Src.zip1 point
-
You might be better to use UIAutomation. Here the code to locate your button : #NoTrayIcon ; https://www.autoitscript.com/forum/topic/201683-ui-automation-udfs/ #include "Includes\CUIAutomation2.au3" #include <Constants.au3> Opt("MustDeclareVars", 1) If @OSVersion <> "WIN_7" Then Exit MsgBox ($MB_SYSTEMMODAL,"","This script only works on Win 7") Local $aMenu = _Systray_SelectOption("Name of your button here") ; <<<<<<<<<<<<<<<<<< change this Func _Systray_SelectOption($sButton) Local $hWnd = WinGetHandle('[Class:Shell_TrayWnd]') If Not $hWnd Then Return SetError(1) Local $hCtrl = ControlGetHandle($hWnd, '', "ToolbarWindow321") ; button must be visible If Not $hCtrl Then Return SetError(2) ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation) If Not IsObj($oUIAutomation) Then Return ConsoleWrite("$oUIAutomation ERR" & @CRLF) ConsoleWrite("$oUIAutomation OK" & @CRLF) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement($pDesktop) $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oDesktop) Then Return ConsoleWrite("$oDesktop ERR" & @CRLF) ConsoleWrite("$oDesktop OK" & @CRLF) ; Get element by handle Local $pElement, $oElement $oUIAutomation.ElementFromHandle($hCtrl, $pElement) $oElement = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) If Not IsObj($oElement) Then Return ConsoleWrite("$oElement ERR" & @CRLF) ConsoleWrite("$oElement OK" & @CRLF) ; Get condition (ControlType = Button) Local $pCondition, $oCondition $oUIAutomation.CreatePropertyCondition($UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition) $oCondition = ObjCreateInterface($pCondition, $sIID_IUIAutomationPropertyCondition, $dtagIUIAutomationPropertyCondition) If Not IsObj($oCondition) Then Return ConsoleWrite("$oCondition ERR" & @CRLF) ConsoleWrite("$oCondition OK" & @CRLF) ; Find all buttons Local $pElementArray, $oElementArray, $iElements $oElement.FindAll($TreeScope_Children, $oCondition, $pElementArray) $oElementArray = ObjCreateInterface($pElementArray, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray) $oElementArray.Length($iElements) If Not IsObj($oElementArray) Then Return ConsoleWrite("$oElementArray ERR" & @CRLF) ConsoleWrite("$oElementArray OK" & @CRLF) ; Get array of buttons Local $aElements[$iElements] For $i = 0 To $iElements - 1 $oElementArray.GetElement($i, $pElement) $aElements[$i] = ObjCreateInterface($pElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) Next ; Get name and position for each button Local $sValue Local $tRect = DllStructCreate("long Left;long Top;long Right;long Bottom") Local $tPoint = DllStructCreate("long X;long Y"), $bBool For $i = 0 To UBound($aElements) - 1 $aElements[$i].GetCurrentPropertyValue($UIA_NamePropertyId, $sValue) ConsoleWrite("Name = " & $sValue) $aElements[$i].CurrentBoundingRectangle($tRect) ConsoleWrite("/ L:" & $tRect.Left & " T:" & $tRect.Top & " R:" & $tRect.Right & " B:" & $tRect.Bottom & @CRLF) $aElements[$i].GetClickablePoint($tPoint, $bBool) If StringInStr($sValue, $sButton) Then MouseClick("Right", $tPoint.X, $tPoint.Y, 1, 1) ConsoleWrite("Found and clicked !" & @CRLF) ExitLoop EndIf Next EndFunc1 point