memerim Posted November 21, 2019 Share Posted November 21, 2019 (edited) Looking for help in a script to search a word and replace for a random word.. Search "1DEF44" and replace for a random word like "1GB319", "3CCD21", but it needs change the same word generated in two local different. This: If $CompName = "120" then Local $CompName = "DESKTOP-1DEF44" Global $e = 120 EndIf If $CompName = "121" then Local $CompName = "DESKTOP-1DEF44" Global $e = 121 EndIf If $CompName = "122" then Local $CompName = "DESKTOP-1DEF44" Global $e = 122 EndIf If $CompName = "DESKTOP-1DEF44" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 1367 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf If $CompName = "DESKTOP-1DEF44" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 4437 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf If $CompName = "DESKTOP-1DEF44" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 757 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf To this: If $CompName = "120" then Local $CompName = "DESKTOP-3XCF21" Global $e = 120 EndIf If $CompName = "121" then Local $CompName = "DESKTOP-7AAE31" Global $e = 121 EndIf If $CompName = "122" then Local $CompName = "DESKTOP-4CCA13" Global $e = 122 EndIf If $CompName = "DESKTOP-3XCF21" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 1367 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf If $CompName = "DESKTOP-7AAE31" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 4437 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf If $CompName = "DESKTOP-4CCA13" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 757 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf Was searching on forum i found this script: Local $String = FileRead('C:\Users\CAIO\Desktop\TXT\SCRIPTS\txt.txt') Local $sStart = 'DESKTOP-' Local $sEnd = 'D' Local $iInit = 1 - 1 ConsoleWrite(Execute("'" & StringRegExpReplace($String, "(?i)(?<=" & $sStart & ")(\d+)(?=" & $sEnd & ".*?)", "'&$iInit+Assign('iInit',$iInit+1)&'") & "'") & @CRLF) I tried randomize each number starting from -1 but the script dont randomize words, and the number increase exponentially 😆 Edited November 21, 2019 by memerim Link to comment Share on other sites More sharing options...
rudi Posted November 22, 2019 Share Posted November 22, 2019 (edited) An easy approach would be to use an INI file, but WTF should be the benefit of manually writing fake values for the CPU to the registry??? [CompNames] 120=DESKTOP-3XCF21|1367 121=DESKTOP-7AAE31|4437 122=DESKTOP-1DEF44|757 #include <Debug.au3> #include <Array.au3> $ini="C:\temp\Computers.ini" $Sect="CompNames" $aInfo=IniReadSection($ini,$Sect) _DebugArrayDisplay($aInfo) $Test="121" $Pointer=_ArraySearch($aInfo,$Test) if @error Then MsgBox(48,"Not defined",$Test & " has no entry in " & $ini) Else $aNewVals=StringSplit($aInfo[$Pointer][1],"|") _DebugArrayDisplay($aNewVals) Exit $NewCompName=$aNewVals[1] $RegKey="HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0" $RegVal="ProcessorNameString" $RegType="REG_SZ" $RegWert="Intel (R) Core(TM) i7-" &$aNewVals[2] & "HQ CPU @ 2.80GHz" RegWrite($RegKey,$RegVal,$RegType,$RegWert) EndIf Rudi Edited November 22, 2019 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Malkey Posted November 26, 2019 Share Posted November 26, 2019 Another method: Uses a function _UniqueAlphaNumeric() that generates a unique text made of specified uppercase, lowercase, or number characters. expandcollapse popup#cs If $CompName = "120" then Local $CompName = "DESKTOP-1DEF44" Global $e = 120 EndIf If $CompName = "121" then Local $CompName = "DESKTOP-1DEF44" Global $e = 121 EndIf If $CompName = "122" then Local $CompName = "DESKTOP-1DEF44" Global $e = 122 EndIf If $CompName = "DESKTOP-1DEF44" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 1367 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf If $CompName = "DESKTOP-1DEF44" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 4437 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf If $CompName = "DESKTOP-1DEF44" Then ; RegWrite("HKLM\HARDWARE\DESCRIPTION\SYSTEM\CENTRALPROCESSOR\0", "ProcessorNameString", "REG_SZ", "Intel (R) Core(TM) i7-" & 757 & "HQ CPU @ 2.80GHz") Call("OPEN_SHORTCUT") EndIf #ce #include <Array.au3> ; https://www.autoitscript.com/forum/topic/200908-search-replace-with-random-values/ Local $sTesStr = StringRegExpReplace(FileRead(@ScriptFullPath), "(?s)^.*#cs\R|\R#ce.*$", "") ; Get test text from block comment, this script. ConsoleWrite($sTesStr & @CRLF & "------------------------------" & @CRLF) ; ------- Create 2D array containg existing value and replacement value ---------- $a = StringRegExp($sTesStr, '(?s)"DESKTOP-([0-9A-Z]{6})"', 3) Local $Arr[6][2] Local $Arr[UBound($a)][2] For $i = 0 To UBound($a) / 2 - 1 $aNewValue = _UniqueAlphaNumeric("n,A,A,An,n,n")[1] $Arr[$i][0] = $a[$i] $Arr[$i][1] = $aNewValue $Arr[$i + (UBound($a) / 2)][0] = $a[$i + (UBound($a) / 2)] $Arr[$i + (UBound($a) / 2)][1] = $aNewValue Next _ArrayDisplay($Arr) ; ---------- Replace existing value with new value ------------- For $i = 0 To UBound($a) - 1 $sTesStr = StringRegExpReplace($sTesStr, "(" & $Arr[$i][0] & ")", $Arr[$i][1], 1) Next ConsoleWrite($sTesStr & @CRLF) ; $sANContent - A coma separated string representing Alpha-Numeric characters: ; "a" - a random lowercase alphabetic character [a-z]. ; "A" - a random uppercase alphabetic character [A-Z]. ; "n" - a random numeric character [0-9]. ; "na" or "an" - Randomly selected either a random numeric character [0-9], or, a random lowercase alphabetic character [a-z]. ; "nA" or "An" - Randomly selected either a random numeric character [0-9], or, a random uppercase alphabetic character [A-Z]. ; Output: A two element array - First element the number of combinations. eg "n,n" returns $aRet[0] = 100 (10*10) - 2 numerals. ; Second element is a unique text. eg. "n,A,a,An,n,n" returns 1AjM92 or 1Aj392. ; Func _UniqueAlphaNumeric($sANContent) Local Static $sUniqTest = "|" Local $sRanText, $iCombinations, $bTF, $aRet[2], $aSelect = StringRegExp($sANContent, "[^,]+", 3) ; $STR_NOCOUNT (2) Do $iCombinations = 1 $sRanText = "" For $i = 0 To UBound($aSelect) - 1 Select Case StringRegExp($aSelect[$i], "\b(n)\b") ; "n" $sRanText &= Random(0, 9, 1) $iCombinations *= 10 Case StringRegExp($aSelect[$i], "\b(a)\b") ; "a" $sRanText &= ChrW(Random(97, 122, 1)) $iCombinations *= 26 Case StringRegExp($aSelect[$i], "\b(A)\b") ; "A" $sRanText &= ChrW(Random(65, 90, 1)) $iCombinations *= 26 Case StringRegExp($aSelect[$i], "\b(an|na)\b") ;"an", "na" $bTF = Random(0, 1, 1) $sRanText &= ($bTF ? Random(0, 9, 1) : ChrW(Random(97, 122, 1))) $iCombinations *= ($bTF ? 10 : 26) Case StringRegExp($aSelect[$i], "\b(An|nA)\b") ;"An", "nA" $bTF = Random(0, 1, 1) $sRanText &= ($bTF ? Random(0, 9, 1) : ChrW(Random(65, 90, 1))) $iCombinations *= ($bTF ? 10 : 26) EndSelect Next If StringInStr($sUniqTest, "|" & $sRanText & "|") = 0 Then $sUniqTest &= $sRanText & "|" ExitLoop 1 EndIf Until 0 $aRet[0] = $iCombinations $aRet[1] = $sRanText Return $aRet EndFunc ;==>_UniqueAlphaNumeric Here is a test example of the _UniqueAlphaNumeric() function. expandcollapse popupLocal $j = 0, $s = "" Do $j += 1 ;$a = _UniqueAlphaNumeric("n,A,A,An,n,n") ; Or $a = _UniqueAlphaNumeric("n,n") $s &= $a[1] & @CRLF Until $j > 200 Or $j > $a[0] - 1 ConsoleWrite($s & "---- Sorted ----" & @CRLF) $s = _StringSortRE($s) ; <--- Used only to check all combinations are generated (when number of combinations is less than 200). ConsoleWrite($s & @CRLF) ConsoleWrite("Number of combinations = " & $a[0] & @CRLF) ; $sANContent - A coma separated string representing Alpha-Numeric characters: ; "a" - a random lowercase alphabetic character [a-z]. ; "A" - a random uppercase alphabetic character [A-Z]. ; "n" - a random numeric character [0-9]. ; "na" or "an" - Randomly selected either a random numeric character [0-9], or, a random lowercase alphabetic character [a-z]. ; "nA" or "An" - Randomly selected either a random numeric character [0-9], or, a random uppercase alphabetic character [A-Z]. ; Output: A two element array - First element the number of combinations. eg "n,n" returns $aRet[0] = 100 (10*10) - 2 numerals. ; Second element is a unique text. eg. "n,A,a,An,n,n" returns 1AjM92 or 1Aj392. ; Func _UniqueAlphaNumeric($sANContent) Local Static $sUniqTest = "|" Local $sRanText, $iCombinations, $bTF, $aRet[2], $aSelect = StringRegExp($sANContent, "[^,]+", 3) Do $iCombinations = 1 $sRanText = "" For $i = 0 To UBound($aSelect) - 1 Select Case StringRegExp($aSelect[$i], "\b(n)\b") ; "n" $sRanText &= Random(0, 9, 1) $iCombinations *= 10 Case StringRegExp($aSelect[$i], "\b(a)\b") ; "a" $sRanText &= ChrW(Random(97, 122, 1)) $iCombinations *= 26 Case StringRegExp($aSelect[$i], "\b(A)\b") ; "A" $sRanText &= ChrW(Random(65, 90, 1)) $iCombinations *= 26 Case StringRegExp($aSelect[$i], "\b(an|na)\b") ;"an", "na" $bTF = Random(0, 1, 1) $sRanText &= ($bTF ? Random(0, 9, 1) : ChrW(Random(97, 122, 1))) $iCombinations *= ($bTF ? 10 : 26) Case StringRegExp($aSelect[$i], "\b(An|nA)\b") ;"An", "nA" $bTF = Random(0, 1, 1) $sRanText &= ($bTF ? Random(0, 9, 1) : ChrW(Random(65, 90, 1))) $iCombinations *= ($bTF ? 10 : 26) EndSelect Next If StringInStr($sUniqTest, "|" & $sRanText & "|") = 0 Then $sUniqTest &= $sRanText & "|" ExitLoop 1 EndIf Until 0 $aRet[0] = $iCombinations $aRet[1] = $sRanText Return $aRet EndFunc ;==>_UniqueAlphaNumeric ; http://www.autoitscript.com/forum/index.php?showtopic=101594&view=findpost&p=722113 Func _StringSortRE($sString, $iDescending = 0, $iNumbers = 0, $d = @CRLF) ; ($d = Delimiters) Local $iCount, $bPass = False StringRegExpReplace($sString, "(" & $d & ")", " ") $iCount = @extended + 1 - StringRegExp($sString, "(" & $d & ")$") ; Trailing delimiter is ignored if present. While Not $bPass $bPass = True For $x = 0 To $iCount - 2 $sItem1 = StringRegExpReplace($sString, "(?s)(([^" & $d & "]+" & $d & "){" & $x & "})([^" & $d & "]+)(.*)", "${3}") ; Get current $x item $sItem2 = StringRegExpReplace($sString, "(?s)(([^" & $d & "]+" & $d & "){" & $x & "})([^" & $d & "]+)(" & $d & ")([^" & $d & "]+)(.*)", "${5}") ; Get the next item after the current $x item If ($iDescending = 0 And $iNumbers <> 0 And Number($sItem1) > Number($sItem2)) Or _ ; (Ascending, Numeric) (0,1) ($iDescending = 0 And $iNumbers = 0 And $sItem1 > $sItem2) Or _ ; (Ascending, Alpha) (0,0) ($iDescending <> 0 And $iNumbers <> 0 And Number($sItem1) < Number($sItem2)) Or _ ; (Descending, Numeric) (1,1) ($iDescending <> 0 And $iNumbers = 0 And $sItem1 < $sItem2) Then ; (Descending, Alpha) (1,0) $sString = StringRegExpReplace($sString, "(?s)(([^" & $d & "]+" & $d & "){" & $x & "})([^" & $d & "]+)(" & $d & ")([^" & $d & "]+)(" & $d & ")?", "${1}${5}${4}${3}${6}") ; Swap $sItem1 and $sItem2 i.e. swap back-reference ${3} and ${5}. $bPass = False EndIf Next WEnd Return $sString EndFunc ;==>_StringSortRE Link to comment Share on other sites More sharing options...
iamtheky Posted November 26, 2019 Share Posted November 26, 2019 $str = '$CompName = "DESKTOP-1DEF44"' & @LF & _ '$CompName = "DESKTOP-1DEF44"' & @LF & _ '$CompName = "DESKTOP-1DEF44"' Do $str = StringReplace($str , "1DEF44" , Hex(random(1 , 16777215 , 1) , 6) , 1) until @extended = 0 msgbox(0, '' , $str) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
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