MightyWeird Posted August 19, 2019 Posted August 19, 2019 (edited) Hi, Junk removal script. I am working on a little script to remove software if it matches a word in a file. I have 1 file with names of programs. For example java 7-zip winrar And a second file with a list of installed programs. PuTTY release 0.71 (64-bit) Adobe Shockwave Player 12.3 I would like if a words matches in de first file with one in the second file, then execute some code. $file = FileOpen("c:\installed.txt", 0) $read = FileRead($file) if StringInStr($read, "7-zip") then msgbox("installed") Only now I need the add the string into an array or something? Can someone Just kick me in the right direction? Edited August 19, 2019 by MightyWeird
Subz Posted August 19, 2019 Posted August 19, 2019 Use FileReadToArray for both, loop through one and use _ArraySearch to find the word in the second array.
MightyWeird Posted August 19, 2019 Author Posted August 19, 2019 Still need to learn arrays and stuff. But after some test and trial came up with this. (should have done this before posting) #RequireAdmin #include <file.au3> $file = FileOpen(@DesktopDir & "\bron.txt", 0) $fileopen = FileOpen("c:\InstallList.txt", 0) $filelijst = FileRead($fileopen) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;MsgBox(0,'',$line,1) if StringInStr($filelijst, $line) then MsgBox(0,'welke',$line,1) ;~ Else ;~ MsgBox(0,'helaaaas',$line,1) endif WEnd FileClose($file) Seems to do the job.
Subz Posted August 19, 2019 Posted August 19, 2019 Untested but maybe something like: #include <Array.au3> Global $g_iSearch, $g_aSearch = FileReadToArray(@ScriptDir & "\Bron.txt") If @error Then Exit MsgBox(4096, "Error", "Error reading Bron.txt" & @CRLF & "Error: " & @error) Global $g_aInstallList = FileReadToArray("C:\InstalledList.txt") If @error Then Exit MsgBox(4096, "Error", "Error reading InstalledList.txt" & @CRLF & "Error: " & @error) For $i = 0 To UBound($g_aSearch) - 1 $g_iSearch = _ArraySearch($g_aInstallList, $g_aSearch[$i]) If $g_iSearch > - 1 Then MsgBox(4096, "Search Item " & $g_aSearch[$i] & " found at line " & $g_iSearch + 1) Next Or search for installed software from registry results: Global $g_aResults, $g_aInstalledSoftware[0][3], $g_aSearch = ["Java", "7-zip", "Winrar"] _InstalledSoftware("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") _InstalledSoftware("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") _ArrayDisplay($g_aInstalledSoftware) For $i = 0 To UBound($g_aSearch) - 1 $g_aResults = _ArrayFindAll($g_aInstalledSoftware, $g_aSearch[$i], 0, 0, 0, 0, 1) _ArrayDisplay($g_aResults) If UBound($g_aResults) - 1 = -1 Then ConsoleWrite("Unable to find: " & $g_aSearch[$i] & @CRLF) Next Func _InstalledSoftware($_sRegRootKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") If StringRight($_sRegRootKey, 1) = "\" Then StringTrimRight($_sRegRootKey, 1) Local $sRegSubKey, $aInstalled, $i = 1 While 1 $sRegSubKey = RegEnumKey($_sRegRootKey, $i) If @error Then ExitLoop $sRegRootKey = $_sRegRootKey & "\" & $sRegSubKey $sDisplayName = RegRead($sRegRootKey, "DisplayName") $sUninstallString = RegRead($sRegRootKey, "UninstallString") If $sDisplayName <> "" And $sUninstallString <> "" Then ReDim $g_aInstalledSoftware[UBound($g_aInstalledSoftware) + 1][3] $g_aInstalledSoftware[UBound($g_aInstalledSoftware) - 1][0] = $sRegRootKey $g_aInstalledSoftware[UBound($g_aInstalledSoftware) - 1][1] = $sDisplayName $g_aInstalledSoftware[UBound($g_aInstalledSoftware) - 1][2] = $sUninstallString EndIf $i += 1 WEnd EndFunc
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