cherdeg
Active Members-
Posts
237 -
Joined
-
Last visited
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
cherdeg's Achievements
Polymath (5/7)
1
Reputation
-
minimen456 reacted to a post in a topic:
WMI - how to authenticate at remote host?
-
Yep, of yours, this is it!!! Easy, simple, obvious. Except if you, like me, can't see the forest for the trees Thank you very much, you made my day!!! The working code: ; AutoIT-Includes #include <Array.au3> ; General Variables Global $r_key = "\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order" Global $r_value = "ProviderOrder" Global $s_source Global $s_target Global $a_Values Global $a_ValuesTemp Global $i_RegWriteResult ; Main ; ================================================================================================== If @OSArch == "X86" Then $r_key = "HKLM" & $r_key If @OSArch == "X64" Then $r_key = "HKLM64" & $r_key ; Read the original Registry Value $s_source = RegRead($r_key, $r_value) If $s_source = "" And @error <> 0 Then ConsoleWrite(@CRLF & "Something went terribly wrong while reading the key, so from now on fear the dark - " & $s_source & ": " & @error & @CRLF) Else ; Backup the original Registry Value $i_RegWriteResult = RegWrite($r_key, $r_value & "_Backup", "REG_SZ", $s_source) If $i_RegWriteResult <> 1 Then ConsoleWrite(@CRLF & "Something went terribly wrong while writing the key, so from now on fear the dark - " & $s_source & ": " & @error & @CRLF) EndIf ; Split to array and delete the relevant elements; all other elements stay untouched and in order $a_Values = StringSplit($s_source, ",", 2) $a_ValuesTemp = $a_Values For $i_i = UBound($a_Values) -1 To 0 Step -1 If $a_Values[$i_i] == "WebClient" Or $a_Values[$i_i] == "npnotes" Then _ArrayDelete($a_ValuesTemp, $i_i) Next _ArrayInsert($a_ValuesTemp, 2, "WebClient") _ArrayInsert($a_ValuesTemp, 3, "npnotes") $a_Values = $a_ValuesTemp ; Write the values back to Registry $s_target = _ArrayToString($a_Values, ",") $i_RegWriteResult = RegWrite($r_key, $r_value, "REG_SZ", $s_target) If $i_RegWriteResult <> 1 Then ConsoleWrite(@CRLF & "Something went terribly wrong while writing the key, so from now on fear the dark - " & $s_source & ": " & @error & @CRLF) Else ConsoleWrite(@CRLF & "The neccessary changes were made..." & @CRLF) EndIf EndIf
-
I do: * Read Registry value's string * Write an Backup of original value to the Registry * Build an array from the original string * Try to resort that array's elements based on the requirements in my OP <<< this is the part I have trouble with * Build a string from the sorted array * Write the string back to the Registry How would you approve the problem with a 2D-Array?
-
Hi, I'm somehow stuck: I've got to resort an array of at least the following five values: "RDPNP", "npnotes", "LanmanWorkstation", "WebClient", "PssoCM32" There are also situations where the array holds more elements. The values "npnotes" and "WebClient" may appear on any postition of the array. The resort has to conform to the following rules: 1.) After the resort no values must be lost or added; the number of values must stay the same. 2.) "npnotes" has to be the value following directly after "WebClient". 3.) "WebClient" should become element 3 or larger (if there are more than "RDPNP" and "LanmanWorkstation" before it). 4.) All other elements should keep their curent order. I'm officially too dumb to solve this seemingly easy job - please help... Best Regards, Chris Edit: Here my code so far - it just doesn't work perfekt. ; AutoIT-Includes #include <Array.au3> ; General Variables Global $r_key = "\SYSTEM\CurrentControlSet\Control\NetworkProvider\Order" Global $r_value = "ProviderOrder" Global $s_source Global $s_target Global $a_Values Global $i_Pos1 Global $i_Pos2 Global $i_RegWriteResult ; Main ; ================================================================================================== If @OSArch == "X86" Then $r_key = "HKLM" & $r_key If @OSArch == "X64" Then $r_key = "HKLM64" & $r_key $s_source = RegRead($r_key, $r_value) If $s_source = "" And @error <> 0 Then ConsoleWrite(@CRLF & "Something went terribly wrong while reading the key, so from now on fear the dark - " & $s_source & ": " & @error & @CRLF) Else ; Backup the original Registry Value $i_RegWriteResult = RegWrite($r_key, $r_value & "_Backup", "REG_SZ", $s_source) If $i_RegWriteResult <> 1 Then ConsoleWrite(@CRLF & "Something went terribly wrong while writing the key, so from now on fear the dark - " & $s_source & ": " & @error & @CRLF) EndIf $a_Values = StringSplit($s_source, ",", 2) For $i_i = 0 To UBound($a_Values) - 1 If $a_Values[$i_i] == "WebClient" Then $i_Pos1 = $i_i If $a_Values[$i_i] == "npnotes" Then $i_Pos2 = $i_i Next If $i_Pos2 <> $i_Pos1+1 Then _ArrayDisplay($a_Values, "Before") If $i_Pos1 == 0 Then _ArrayInsert($a_Values, $i_Pos1+3, $a_Values[$i_Pos1]) _ArrayDelete($a_Values, $i_Pos1) _ArrayInsert($a_Values, $i_Pos1+4, $a_Values[$i_Pos2]) _ArrayDelete($a_Values, $i_Pos2+1) _ArrayDisplay($a_Values, "After-0") ElseIf UBound($a_Values)-1 >= $i_Pos1+1 Then _ArrayInsert($a_Values, $i_Pos1+1, $a_Values[$i_Pos2]) _ArrayDelete($a_Values, $i_Pos2) _ArrayDisplay($a_Values, "After-1") ElseIf UBound($a_Values)-1 = $i_Pos1 Then _ArrayInsert($a_Values, $i_Pos2, $a_Values[$i_Pos1]) _ArrayDelete($a_Values, UBound($a_Values)-1) _ArrayDisplay($a_Values, "After-2") EndIf $s_target = _ArrayToString($a_Values, ",") $i_RegWriteResult = RegWrite($r_key, $r_value, "REG_SZ", $s_target) If $i_RegWriteResult <> 1 Then ConsoleWrite(@CRLF & "Something went terribly wrong while writing the key, so from now on fear the dark - " & $s_source & ": " & @error & @CRLF) Else ConsoleWrite(@CRLF & "The neccessary changes were made..." & @CRLF) EndIf Else ConsoleWrite(@CRLF & "Everything already in perfect state..." & @CRLF) EndIf EndIf
-
Hi! Fantastic work, water: Thank you so much!!! One question: I need to access an MS-DNS and alter / create / delete DNS Records. Any clues? Best Regards, Chris
-
List Running Tasks on Remote Machine
cherdeg replied to Naveed's topic in AutoIt General Help and Support
Hello there...eventually this could be of some interest: Your version only works perfect if locally logged on user account is existing on the remote machine and has permissions there. Here an example how to check for a certain service on a remote machine using an other than the locally logged in user: Global $h_wbemFlagReturnImmediately = 0x10 Global $h_wbemFlagForwardOnly = 0x20 Global $h_wbemFlags = $h_wbemFlagReturnImmediately + $h_wbemFlagForwardOnly Global $a_Hosts[3] = ["HOST-1", "HOST-2", "HOST-3"] ; change here to match your environment Global $a_Processes[4] = ["process-1.exe", "process-2.exe", "process-3.exe", "regedit.exe"] Global $s_AdminUser = "Administrator" ; change here to match your environment Global $s_AdminPW = "password" ; change here to match your environment For $i=0 To UBound($a_Hosts) -1 $s_ProcessRunning = _CheckRemoteProcesses($a_Hosts[$i], $a_Processes, $s_AdminUser, $s_AdminPW) Next Func _CheckRemoteProcesses($s_Host, $a_Processes, $s_AdminUser, $s_AdminPW) Local $o_RemoteWMIService, $o_Process, $o_colProcesses Local $s_ProcessExists = "NO" Local $i_Result = 0, $s_ProcessRunning ; Create an object for the remote host's WMI interface and authenticate against it $o_SWbemLocator = ObjCreate("WbemScripting.SWbemLocator") If IsObj($o_SWbemLocator) Then $o_RemoteWMIService = $o_SWbemLocator.ConnectServer($s_Host, "root\CIMV2", $s_AdminUser, $s_AdminPW) If IsObj($o_RemoteWMIService) Then $o_colProcesses = $o_RemoteWMIService.ExecQuery("Select * from Win32_Process", "WQL", $h_wbemFlags) If IsObj($o_colProcesses) Then For $o_elements In $o_colProcesses For $i=0 To UBound($a_Processes) -1 If $o_elements.Name == $a_Processes[$i] Then ConsoleWrite(@CRLF & $s_Host & ": Process " & $a_Processes[$i] & " exists." & @CRLF) $s_ProcessExists = "YES" EndIf Next Next EndIf If $s_ProcessExists = "NO" Then ConsoleWrite(@CRLF & $s_Host & ": No process found." & @CRLF) Return $s_ProcessExists Else ConsoleWrite(@CRLF & $s_Host & ": Probably wrong password or account disabled/inactive.") Return $s_ProcessExists = "Error" EndIf Else ConsoleWrite(@CRLF & ": Can't setup SWbemLocator object.") Return $s_ProcessExists = "Error" EndIf EndFunc ;==>_CheckRemoteProcesses Best Regards, Chris -
I need to remark that the work to "Parallize PSexec" was done mostly by MANADAR for a function to ping lots of hosts in parallel. I simply modified it to suit my needs. It's always nice to get credit, but this time all the credit belongs to MANADAR.
-
-i helps - thank you! -d can't be used because in my case: in a later iteration of this proof of concept I'm gonna copy certain result files from the remote machines; which can only be done after psexec has terminated after the "remote executed tool" is finished.
-
Dear Ladies and Gentlemen, I currently try to run one of our check-tools on several remote machines in parallel. The final goal is to have a "stack", a pre-defined number of psexec-processes (dependent of the machine's performance), running in parallel. Manadar once helped me greatly to parallelize the ping command, and I try to do the same with psexec, but I'm stuck: The tool hangs after executing the first stack of commands. PSEXECSVC is started on the remote machines, but then nothing happens. If the service is killed manually there, the next stack of machines is processed seemingly correctly. Here's my current code - does somebody of you have any idea? #include <Constants.au3> Global $s_CRLF = @CRLF Global $a_Hosts[3] = ["HOST1", "HOST2", "HOST3"] ; replace with existing hosts Global $s_RemoteCMD = "net user" ; just an example _CheckOnlineStatus($a_Hosts, 2) ; Function Name _CheckOnlineStatus() ; ================================================================================================== ; ; Function Name: _CheckOnlineStatus() ; Description: Use psexec to execute checker on several systems ; Parameter(s): $a_Hostnames, $i_MaxProcess ; Requirement(s): AutoIt 3.3 ; Return Value(s): Currently none - proof of concept ; Author(s): Manadar, cs-it-solutions ; ; ================================================================================================== Func _CheckOnlineStatus($a_Hosts, $i_MaxProcess) ; Prepare the asynchronous execution Local Const $MAX_PROCESS = $i_MaxProcess ; We spawn a maximum of "$i_MaxProcess" processes at once Local $a_process[$MAX_PROCESS] ; An array to keep a reference to spawned processes; the following loop we fill it with 0 For $i = 0 To UBound($a_process) - 1 $a_process[$i] = 0 Next Local $i = 0 ; A pointer to run through the $a_Hosts array Local $i_finished = 0 While True ; Check on the current processes, and look if there is one finished for use with our next host in line (from $a_Hosts) For $n = 0 To UBound($a_process) - 1 If ($i <> UBound($a_Hosts) And $a_process[$n] == 0) Then ; Check if we need a spot, and there is an existing spot ; There is an empty spot $a_process[$n] = _MSpsexec($a_Hosts[$i]) $i += 1 Else ; Something is running here, let's check on the output If ($a_process[$n] <> 0 And _MSpsexecIsReady($a_process[$n])) Then ; We have an output here, let's get it! $s_hostname = _MSpsexecGetHostname($a_process[$n]) $i_success = _MSpsexecGetResult($a_process[$n]) If ($i_success == "Yes") Then ; Do some command line output ConsoleWrite("PSexec: Worked on " & $s_hostname & "." & $s_CRLF) Else ; Do some command line output ConsoleWrite("PSexec: Didn't work on " & $s_hostname & "." & $s_CRLF) EndIf ; Free up an empty space for the next machine $a_process[$n] = 0 $i_finished += 1 If ($i_finished == UBound($a_Hosts)) Then ExitLoop 2 ; Return EndIf EndIf EndIf Next Sleep(50) ; Give existing commands some time to process the request WEnd EndFunc ;==>_CheckOnlineStatus ; Function Name _MSpsexec() ; ================================================================================================== ; ; Function Name: _MSpsexec() ; Description: ; Parameter(s): ; Requirement(s): ; Return Value(s): ; Author(s): Manadar, cs-it-solutions ; ; ================================================================================================== Func _MSpsexec($hostname, $timeout = 50) Local $return_struc[4] ; [0] = Successful Execution: Yes/No ; [1] = The hostname originally used ; [2] = Process handle (for internal use only) ; [3] = Buffer (for internal use only) $s_PsexecCMD = "psexec /accepteula \\" & $hostname & " -u " & $hostname & "\Administrator -p PASSWORD " & $s_RemoteCMD ConsoleWrite($s_PsexecCMD & $s_CRLF) $return_struc[1] = $hostname $return_struc[2] = Run($s_PsexecCMD, "", @SW_HIDE, $STDOUT_CHILD) Return $return_struc EndFunc ;==>_MSpsexec ; Function Name _MSpsexecIsReady() ; ================================================================================================== ; ; Function Name: _MSpsexecIsReady() ; Description: ; Parameter(s): ; Requirement(s): ; Return Value(s): ; Author(s): Manadar ; ; ================================================================================================== Func _MSpsexecIsReady(ByRef $return_struc) Return ___MSpsexecReadOutput($return_struc) EndFunc ;==>_MSpsexecIsReady ; Function Name _MSpsexecGetResult() ; ================================================================================================== ; ; Function Name: _MSpsexecGetResult() ; Description: ; Parameter(s): ; Requirement(s): ; Return Value(s): ; Author(s): Manadar ; ; ================================================================================================== Func _MSpsexecGetResult($return_struc) Return $return_struc[0] EndFunc ;==>_MSpsexecGetResult ; Function Name _MSpsexecGetHostname() ; ================================================================================================== ; ; Function Name: _MSpsexecGetHostname() ; Description: ; Parameter(s): ; Requirement(s): ; Return Value(s): ; Author(s): Manadar ; ; ================================================================================================== Func _MSpsexecGetHostname($return_struc) Return $return_struc[1] EndFunc ;==>_MSpsexecGetHostname ; Function Name ___MSpsexecReadOutput() ; ================================================================================================== ; ; Function Name: ___MSpsexecReadOutput() ; Description: ; Parameter(s): ; Requirement(s): ; Return Value(s): ; Author(s): Manadar, cs-it-solutions ; ; ================================================================================================== ; Internal use only Func ___MSpsexecReadOutput(ByRef $return_struc) $data = StdoutRead($return_struc[2]) If (@error) Then ___MSpsexecParseResult($return_struc) Return 1 Else $return_struc[3] &= $data Return 0 EndIf EndFunc ;==>___MSpsexecReadOutput ; Function Name ___MSpsexecParseResult() ; ================================================================================================== ; ; Function Name: ___MSpsexecParseResult() ; Description: ; Parameter(s): ; Requirement(s): ; Return Value(s): ; Author(s): Manadar, cs-it-solutions ; ; ================================================================================================== ; Internal use only Func ___MSpsexecParseResult(ByRef $return_struc) $result = StringRegExp($return_struc[3], "error code ([0-1]*)", 3) If @error Then $return_struc[0] = "No" Else $return_struc[0] = "Yes" EndIf EndFunc ;==>___MSpsexecParseResult Best Regards, Chris
-
Problem with Encryption/Decryption
cherdeg replied to cherdeg's topic in AutoIt General Help and Support
If you care, you care. If you don't, you don't. I was just randomly picking a phrase. -
Problem with Encryption/Decryption
cherdeg replied to cherdeg's topic in AutoIt General Help and Support
Then only left for me is desperate hope that you aren't pissed... -
Problem with Encryption/Decryption
cherdeg replied to cherdeg's topic in AutoIt General Help and Support
Hey Guys, thank you all - everything you say may be correct. And indeed, _Crypt_DeriveKey, start and stop of encryption isn't needed. Now it works...but it's still a riddle for me that it didn't before... Encryption: #include <Crypt.au3> Local $s_IniFile = "test.ini" $s_Password = InputBox("Password Encrypter", "Please enter the password to encrypt: ") $s_Hash = _Crypt_EncryptData($s_Password, "Arschloch-Karte17", $CALG_RC4) ClipPut($s_Hash) IniWrite($s_IniFile, "General", "RemoteUserPasswordHash", $s_Hash) MsgBox("", "Password Encrypter", "Resulting hash: " & $s_Hash & @CRLF & @CRLF & _ "The INI-File was updated with the generated hash." & @CRLF & _ "Also the hash was copied to the clipboard.") Decryption: #include <Crypt.au3> Local $s_RemoteUserPasswordHash = IniRead("test.ini", "General", "RemoteUserPasswordHash", "") Local $b_Encrypted = Binary($s_RemoteUserPasswordHash) If $b_Encrypted <> "" Then $s_RemotePassword = BinaryToString(_Crypt_DecryptData($b_Encrypted, "Arschloch-Karte17", $CALG_RC4)) Else ConsoleWrite(@CRLF & "No hash found in the INI-File!") EndIf ClipPut($s_RemotePassword) MsgBox("", "Password Decrypter", "Resulting password: " & $s_RemotePassword & @CRLF & @CRLF & _ "The password was copied to the clipboard.") Thank you all and...have a great weekend!!! Regards, Chris -
Problem with Encryption/Decryption
cherdeg replied to cherdeg's topic in AutoIt General Help and Support
Is Valik eventually not a girl? I don't know him/her personally, and "Valik" is neither male nor female. He/She always has Avatar pictures with girls...so? The passphrase was used completely unintentional and without any spirit of mischief. I didn't mean to tread on him/her. Now that that's cleared, do you have some advice regarding the problem? -
Hello Pals, This is my code: #include <Crypt.au3> Global $s_IniFile = "test.ini" ;~ $s_RemoteUserPasswordHash = IniRead($s_IniFile, "General", "RemoteUserPasswordHash", "") ;~ Local $b_Encrypted = Binary("$s_RemoteUserPasswordHash") Local $b_Encrypted = Binary("0x4AFFF9D9ECC556D90AF00046") If $b_Encrypted <> "" Then _Crypt_Startup() $h_Key = _Crypt_DeriveKey("Arschloch-Karte17", $CALG_RC4) _Crypt_DestroyKey($h_Key) _Crypt_Shutdown() $s_RemotePassword = BinaryToString(_Crypt_DecryptData($b_Encrypted, $h_Key, $CALG_RC4)) Else ConsoleWrite(@CRLF & "No hash found in the INI-File!") EndIf MsgBox("", "Password", $s_RemotePassword)If only (!!!) this line: ;~ $s_RemoteUserPasswordHash = IniRead($s_IniFile, "General", "RemoteUserPasswordHash", "")...is uncommented (nothing else!!!), the hash is not correctly decrypted to the correct value of "ValikIsAGirl", no matter if the inifile/key/value exist - and even although $s_RemoteUserPasswordHash isn't used further. Why?!?!?!? Me = totally clueless. Is this a Friday's problem trying to tell me to call it a day and go for the weekend? Regards, Chris
-
BTW: none of the variants here does exitloop for me on pressing ENTER.
-
Thank you very much. That was fast. Delete the thread, if you like to.