Jump to content

DonChunior

Active Members
  • Posts

    90
  • Joined

  • Last visited

Profile Information

  • Location
    Austria
  • Interests
    CAD, Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

DonChunior's Achievements

  1. Hello @Danyfirex and @Nine, thank you both COM professionals - your solutions work! What would I do without specialists like you? I would have to stay stupid forever. πŸ€— Best regards from Austria, DonChunior
  2. Hi @Nine, thanks for the tip! πŸ‘ With the interface INetworkListManager it works fine now. But with the interface INetworkConnection it still doesn't work: Opt("MustDeclareVars", 1) Main() Func Main() Local Const $tagIDispatch = _ "GetTypeInfoCount hresult(uint_ptr*);" & _ "GetTypeInfo hresult(uint;dword;ptr*);" & _ "GetIDsOfNames hresult(struct*;wstr*;uint;dword;long_ptr*);" & _ "Invoke hresult(long;struct*;dword;word;struct*;variant*;ptr*;uint_ptr*);" Local Const $sCLSID_NetworkListManager = "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}" Local Const $sIID_INetworkConnection = "{DCB00005-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_INetworkConnection = _ $tagIDispatch & _ "GetNetwork hresult(ptr*);" & _ "IsConnectedToInternet hresult(short*);" & _ "IsConnected hresult(short*);" & _ "GetConnectivity hresult(int_ptr*);" & _ "GetConnectionId hresult(struct*);" & _ "GetAdapterId hresult(struct*);" & _ "GetDomainType hresult(int_ptr*);" Local $oNLM_INetworkConnection = ObjCreateInterface($sCLSID_NetworkListManager, $sIID_INetworkConnection, $sTag_INetworkConnection) ConsoleWrite("ObjCreateInterface: @error = " & @error & @CRLF) EndFunc Do you have any idea what the problem is?
  3. Hello everyone, first of all, thanks to everyone who has taken the trouble to deal with my problem! ☺️ I have now tried the approach with ObjCreateInterface. For the interface INetworkListManager this works perfectly at first sight, the @error has the value 0 after the call of ObjCreateInterface. Here is the corresponding code snippet: #include <StructureConstants.au3> Opt("MustDeclareVars", 1) Main() Func Main() Local Const $sCLSID_NetworkListManager = "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}" Local Const $sIID_INetworkListManager = "{DCB00000-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_INetworkListManager = _ "GetNetworks hresult(int;ptr*);" & _ "GetNetwork hresult(" & $tagGUID & ";ptr*);" & _ "GetNetworkConnections hresult(ptr*);" & _ "GetNetworkConnection hresult(" & $tagGUID & ";ptr*);" & _ "IsConnectedToInternet hresult(short*);" & _ "IsConnected hresult(short*);" & _ "GetConnectivity hresult(int_ptr*);" & _ "SetSimulatedProfileInfo hresult(struct*);" & _ "ClearSimulatedProfileInfo hresult();" Local $oNLM_INetworkListManager = ObjCreateInterface($sCLSID_NetworkListManager, $sIID_INetworkListManager, $sTag_INetworkListManager) ConsoleWrite("ObjCreateInterface: @error = " & @error & @CRLF) EndFunc But it doesn't work with the INetworkConnection interface. Here @error has the value 1 after calling ObjCreateInterface. Here is also the corresponding code snippet: Opt("MustDeclareVars", 1) Main() Func Main() Local Const $sCLSID_NetworkListManager = "{DCB00C01-570F-4A9B-8D69-199FDBA5723B}" Local Const $sIID_INetworkConnection = "{DCB00005-570F-4A9B-8D69-199FDBA5723B}" Local Const $sTag_INetworkConnection = _ "GetNetwork hresult(ptr*);" & _ "IsConnectedToInternet hresult(short*);" & _ "IsConnected hresult(short*);" & _ "GetConnectivity hresult(int_ptr*);" & _ "GetConnectionId hresult(struct*);" & _ "GetAdapterId hresult(struct*);" & _ "GetDomainType hresult(int_ptr*);" Local $oNLM_INetworkConnection = ObjCreateInterface($sCLSID_NetworkListManager, $sIID_INetworkConnection, $sTag_INetworkConnection) ConsoleWrite("ObjCreateInterface: @error = " & @error & @CRLF) EndFunc Here are the relevant lines from the file netlistmgr.idl: […] // GUID Definitions // // DCB00000-570F-4A9B-8D69-199FDBA5723B INetworkListManager // DCB00001-570F-4A9B-8D69-199FDBA5723B INetworkListManagerEvents // // DCB00002-570F-4A9B-8D69-199FDBA5723B INetwork // DCB00003-570F-4A9B-8D69-199FDBA5723B IEnumNetworks // DCB00004-570F-4A9B-8D69-199FDBA5723B INetworkEvents // // DCB00005-570F-4A9B-8D69-199FDBA5723B INetworkConnection // DCB00006-570F-4A9B-8D69-199FDBA5723B IEnumNetworkConnections // DCB00007-570F-4A9B-8D69-199FDBA5723B INetworkConnectionEvents // // DCB00008-570F-4A9B-8D69-199FDBA5723B INetworkCostManager // DCB00009-570F-4A9B-8D69-199FDBA5723B INetworkCostManagerEvents // // DCB0000a-570F-4A9B-8D69-199FDBA5723B INetworkConnectionCost // DCB0000b-570F-4A9B-8D69-199FDBA5723B INetworkConnectionCostEvents // // ... reserved // DCB000FF-570F-4A9B-8D69-199FDBA5723B Reserved // // DCB00D01-570F-4A9B-8D69-199FDBA5723B Library: NetworkListManager // DCB00C01-570F-4A9B-8D69-199FDBA5723B CoClass: CNetworkListManager […] [ uuid(DCB00000-570F-4A9B-8D69-199FDBA5723B), helpstring("Network List Manager"), object, oleautomation, pointer_default(unique), dual ] interface INetworkListManager : IDispatch { typedef [v1_enum] enum NLM_ENUM_NETWORK { NLM_ENUM_NETWORK_CONNECTED = 0x01, NLM_ENUM_NETWORK_DISCONNECTED = 0x02, NLM_ENUM_NETWORK_ALL = 0x03 } NLM_ENUM_NETWORK; [id(1), helpstring("Enumerate the list of networks in your compartment.")] HRESULT GetNetworks ([in] NLM_ENUM_NETWORK Flags, [out, retval] IEnumNetworks **ppEnumNetwork); [id(2), helpstring("Get a network given a Network ID.")] HRESULT GetNetwork ([in] GUID gdNetworkId, [out, retval] INetwork **ppNetwork); [id(3), helpstring("Enumerate the complete list of all connections in your compartment.")] HRESULT GetNetworkConnections ([out, retval] IEnumNetworkConnections **ppEnum); [id(4), helpstring("Get a network connection by a Network Connection ID.")] HRESULT GetNetworkConnection ([in] GUID gdNetworkConnectionId, [out, retval] INetworkConnection **ppNetworkConnection); [propget, id(5), helpstring("Returns whether this machine has Internet connectivity.")] HRESULT IsConnectedToInternet([out, retval] VARIANT_BOOL* pbIsConnected); [propget, id(6), helpstring("Returns whether this machine has any network connectivity.")] HRESULT IsConnected([out, retval] VARIANT_BOOL* pbIsConnected); [id(7), helpstring("Returns the aggregated connectivity state of all networks on this machine.")] HRESULT GetConnectivity([out, retval] NLM_CONNECTIVITY* pConnectivity); [id(8), helpstring("Sets simulated connection profile information.")] HRESULT SetSimulatedProfileInfo([in] NLM_SIMULATED_PROFILE_INFO *pSimulatedInfo); [id(9), helpstring("Clear simulated cost data, if it has been set.")] HRESULT ClearSimulatedProfileInfo(); } […] [ uuid(DCB00005-570F-4A9B-8D69-199FDBA5723B), helpstring("Network Connection"), object, oleautomation, pointer_default(unique), dual ] interface INetworkConnection : IDispatch { [id(1), helpstring("Returns the associated network of this connection.")] HRESULT GetNetwork ([out, retval] INetwork **ppNetwork); [propget, id(2), helpstring("Returns whether this network connection has Internet connectivity.")] HRESULT IsConnectedToInternet([out, retval] VARIANT_BOOL* pbIsConnected); [propget, id(3), helpstring("Returns whether this network connection has any network connectivity.")] HRESULT IsConnected([out, retval] VARIANT_BOOL* pbIsConnected); [id(4), helpstring("Returns the connectivity state of this network connection.")] HRESULT GetConnectivity([out, retval] NLM_CONNECTIVITY* pConnectivity); [id(5), helpstring("Returns a unique identifer for this connection.")] HRESULT GetConnectionId ([out, retval] GUID *pgdConnectionId); [id(6), helpstring("Returns the network adapter used by this connection. There might be multiple connections using the same AdapterId.")] HRESULT GetAdapterId ([out, retval] GUID *pgdAdapterId); [id(7), helpstring("Returns the domain type of this network connection.")] HRESULT GetDomainType ([out, retval] NLM_DOMAIN_TYPE *pDomainType); } […] Based on this, I can't find any error in my code. πŸ˜’
  4. But have you uncommented the mentioned lune in the code? πŸ€”
  5. I'm playing around a bit with the Network List Manager COM interface. Now I have a simple example where I first create the COM object and then iterate over the network connections. Determining and outputting the domain type of the individual connections is no problem, but when determining the GUID of the network adapter I get an error: To reproduce my problem, just uncomment the corresponding line from the following example code: Opt("MustDeclareVars", 1) Main() Func Main() ; Create Network List Manager object Local $oNLM = ObjCreate("{DCB00C01-570F-4A9B-8D69-199FDBA5723B}") ; Get the list of network connections Local $aoNC = $oNLM.GetNetworkConnections For $oNC In $aoNC ; Get domain type of network connection Local $iDT = $oNC.GetDomainType ConsoleWrite("DomainType = " & $iDT & @CRLF) ; Uncommenting following code line to get the adapter ID of network connection leads to error ; $oNC.GetAdapterId Next EndFunc Why does getting the adapter ID not work? πŸ€”
  6. Hello @water, thanks, that looks like a good starting point for further activities. Regards, DonChunior
  7. In my Network and Sharing center you can see (see screenshot) that I have an active domain network. Is there a way to … determine the active networks with AutoIt, find out whether one of them is a domain network and if one is found, obtain the IP address associated with it? In my opinion, you could also go the other way round and … collect the IP addresses of the macros @IPAddress1 to 4 and check each address to see whether it belongs to an active domain network. Regards, DonChunior
  8. Hello @water, thanks for the explanation. By escaping the individual bytes, it finally works with the LDAP filter. πŸ‘ In Microsoft's TechNet Wiki Archive I found further documentation of this facts: Active Directory: LDAP Syntax Filters | Microsoft Learn I created a small auxiliary function for escaping a binary GUID: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AD_EscapeGUIDBytes ; Description ...: Returns the escaped string of a GUID for use in an LDAP filter. ; Syntax ........: _AD_EscapeGUIDBytes(Const Byref $dGUID) ; Parameters ....: $dGUID - [in/out and const] a binary variant value. ; Return values .: Success - Escaped GUID ; Failure - 0, sets @error to: ; |1 - GUID is not 128 bits (= 32 nibbles) long. @extended = 0 ; Author ........: DonChunior ; Modified ......: ; Remarks .......: Byte arrays, like the objectGUID attribute, can be represented as a series of escaped hexadecimal bytes. ; Related .......: _AD_GetObjectsInOU ; Link ..........: https://learn.microsoft.com/en-us/archive/technet-wiki/5392.active-directory-ldap-syntax-filters ; Example .......: Yes ; =============================================================================================================================== Func _AD_EscapeGUIDBytes(Const ByRef $dGUID) Local Const $iNibblesPerGUID = 32 Local Const $iNibblesPerByte = 2 Local Const $sGUID = Hex($dGUID) If StringLen($sGUID) <> $iNibblesPerGUID Then Return SetError(1, 0, 0) Local $sEscapedGUID = "" For $i = 1 To $iNibblesPerGUID Step $iNibblesPerByte $sEscapedGUID &= "\" $sEscapedGUID &= StringMid($sGUID, $i, $iNibblesPerByte) Next Return $sEscapedGUID EndFunc ;==>_AD_EscapeGUIDBytes Maybe you'd like to add it to your AD UDF along with the attached usage example? _AD_EscapeGUIDBytes.au3
  9. If I use a program to read the AD attributes mail and objectGUID from an AD account, I can't find the original AD account again using the _AD_GetObjectsInOU function and the objectGUID attribute. The example program below works if I use _AD_GetObjectsInOU in combination with mail: _ArrayDisplay shows me again the account I defined in the variable $sUsername. However, if I use the _AD_GetObjectsInOU in combination with objectGUID and comment out the line above, nothing is displayed. What is my mistake here? #include <AD.au3> Opt("MustDeclareVars", 1) Main() Func Main() Local $sUsername = "abc" _AD_Open("", "", "DC=xyz,DC=i", "xyz.i:3269", "CN=Configuration,DC=xyz,DC=i", $ADS_SECURE_AUTH + $ADS_USE_SSL) Local $sMail = _AD_GetObjectAttribute($sUsername, "mail") ConsoleWrite("mail=" & $sMail & @CRLF) Local $sObjectGUID = _AD_GetObjectAttribute($sUsername, "objectGUID") ConsoleWrite("objectGUID=" & $sObjectGUID & @CRLF) Local $aObjectsInOU = _AD_GetObjectsInOU("", "(mail=" & $sMail & ")") ;~ Local $aObjectsInOU = _AD_GetObjectsInOU("", "(objectGUID=" & $sObjectGUID & ")") ConsoleWrite("@error=" & @error & ", @extended=" & @extended & @CRLF) _AD_Close() _ArrayDisplay($aObjectsInOU) EndFunc
  10. I only had to slightly adjust the code in two places so that it now works as expected. πŸ™‚ Line 28 now reads like this: RunWait('cmdkey /generic:"' & $sTarget & '" /user:DummyUserName /pass:"' & String($dData) & '"') And line 45 now reads like this: $dData = _Crypt_DecryptData(Binary($aData[1]), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) The complete script now looks like this: #include <Crypt.au3> #include <WinAPIDlg.au3> Main() Func Main() Local $sString = "" Local Const $sCryptKey = "=>J7U\DJ/qFun?Co" Local $dData = Binary("") Local Const $sTarget = "Dummy Credentials" Local $aData = 0 ; Get a string that will be used for testing the encryption and decryption $sString = InputBox("String Input", "Enter a test string:") ConsoleWrite("$sString: " & $sString & @CRLF) _Crypt_Startup() ; Encrypt the previousely entered string $dData = _Crypt_EncryptData(StringToBinary($sString, $SB_UTF8), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_EncryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) ; Store the encrypted string in the Credential Manager RunWait('cmdkey /generic:"' & $sTarget & '" /user:DummyUserName /pass:"' & String($dData) & '"') ; Read the data stored in the Credential Manager $aData = _WinAPI_ShellUserAuthenticationDlg( _ "", _ "", _ "", _ "", _ $sTarget, _ $CREDUI_FLAGS_GENERIC_CREDENTIALS) ConsoleWrite("$aData[0]: " & $aData[0] & @CRLF) ConsoleWrite("$aData[1]: " & $aData[1] & @CRLF) ; Delete the entry in the Credential Manager RunWait('cmdkey /delete:"' & $sTarget & '"') ; Decrypt the data read from the Credential Manager $dData = _Crypt_DecryptData(Binary($aData[1]), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_DecryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) _Crypt_Shutdown() ; Convert the data back to a string $sString = BinaryToString($dData, $SB_UTF8) ConsoleWrite("$sString: " & $sString & @CRLF) EndFunc ;==>Main
  11. That would be the more elaborate plan B if I can't find an easier way. Does anyone else have any ideas?
  12. Okay, got it. πŸ‘Œ It helps quite a bit to know the cause. Now I wonder how to get the encrypted data stored in the Credential Manager. πŸ™„ Anybody have any ideas?
  13. I've got a problem where I just can't figure out the cause. πŸ€” The simple script below does the following: At the beginning, you can enter a test string. This is then encrypted and temporarily stored in the Credential Manager. Then the data is read again from the Credential Manager and decrypted. Many words (e.g. DonChunior or AutoIt) correspond to the originally entered string after decryption. But for some, for whatever reason I can't figure out, it doesn't?! For example: VeryLongString (the decrypted string is VeryLongStrin) ILoveAutoIt (the decrypted string is ILoveAutoI) WhatIsHereTheProblem (the decrypted string is WhatIsHere) I hope some of you specialists can help me. πŸ™ #include <Crypt.au3> #include <WinAPIDlg.au3> Main() Func Main() Local $sString = "" Local Const $sCryptKey = "=>J7U\DJ/qFun?Co" Local $dData = Binary("") Local Const $sTarget = "Dummy Credentials" Local $aData = 0 ; Get a string that will be used for testing the encryption and decryption $sString = InputBox("String Input", "Enter a test string:") ConsoleWrite("$sString: " & $sString & @CRLF) _Crypt_Startup() ; Encrypt the previousely entered string $dData = _Crypt_EncryptData(StringToBinary($sString, $SB_UTF8), StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_EncryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) ; Store the encrypted string in the Credential Manager RunWait('cmdkey /generic:"' & $sTarget & '" /user:DummyUserName /pass:"' & BinaryToString($dData) & '"') ; Read the data stored in the Credential Manager $aData = _WinAPI_ShellUserAuthenticationDlg( _ "", _ "", _ "", _ "", _ $sTarget, _ $CREDUI_FLAGS_GENERIC_CREDENTIALS) ConsoleWrite("$aData[0]: " & $aData[0] & @CRLF) ConsoleWrite("$aData[1]: " & $aData[1] & @CRLF) ; Delete the entry in the Credential Manager RunWait('cmdkey /delete:"' & $sTarget & '"') ; Decrypt the data read from the Credential Manager $dData = _Crypt_DecryptData($aData[1], StringToBinary($sCryptKey, $SB_UTF8), $CALG_RC4) If @error Then ConsoleWrite("_Crypt_DecryptData: @error = " & @error & @CRLF) Exit EndIf ConsoleWrite("$dData: " & $dData & @CRLF) _Crypt_Shutdown() ; Convert the data back to a string $sString = BinaryToString($dData, $SB_UTF8) ConsoleWrite("$sString: " & $sString & @CRLF) EndFunc ;==>Main
  14. I can confirm that points 1 to 4 are working properly. Thank you for the quick solution to my problem. I can't say anything about point 5 because I don't understand what is meant by it.
×
×
  • Create New...