Doxie Posted December 10, 2004 Share Posted December 10, 2004 (edited) Hi, Sorry for the title, but i start to get panic here. I got 1 hour and 15 minutes to report to my manager how many users got the latest patch from Microsoft installed. I got a log file from each user computer, that is stored on the server, from the users last login. In the log file, i can see if the patch has been installed. It looks like this: [Win32_QuickFixEngineering] HotFixID=KB889293-IE6SP1-20041111.235619 The file is named computername.Log How do i make a script that search in all the files, for the value above and report back: [Win32_NetworkLoginProfile] UserAccount=name If its not installed. It would be nice if i could get this list in another txt file, or maybe in a copy/paste window. I have made a similiar script earlier for the same kind of files, but now i cant find that script. Thanks in advance EDIT I found this code on my computer, can i use something similiar? This code is only to search a specific file, and not serveral files. $search = "KB887623" $file = FileOpen("c:\version.txt", 0) If $file = -1 Then;error opening file MsgBox(0, "Fatal error", "Unable to open file... quitting") Exit EndIf $i = 1;set the line counter variable While 1 $line = FileReadLine($file, $i);get the current line and store to a var If @error Then ExitLoop;EOF reached with no success If StringInStr($line, $search) Then;we found the text, so tell user and exit $Patch1 = "Yes" MsgBox(0, "Text found", "We found the patch") Exit EndIf $i = $i + 1 WEnd MsgBox(0, "Text not found", "Sorry, your requested text was not found on any line") Edited December 10, 2004 by Doxie Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted December 10, 2004 Author Share Posted December 10, 2004 (edited) I found a code and modified it, but its not working, why? ;''Settings'' $folder = '\\eu2svr01\logfile$\Inventory\Stockholm\';-- With trailing backslash $filenames = '*.Log';-- Wildcards accepted. ;''Code'' $Handle = FileFindFirstFile($folder & $filenames) If $Handle = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $c = 0 While 1 $file = $folder & FileFindNextFile($Handle) If @error Then ExitLoop $time=IniRead($file,"Win32_QuickFixEngineering","ServicePackInEffect","") If $time = "KB889293-IE6SP1-20041111.235619" Then $c = $c + 1 IniWrite("C:\check.ini","test","logged","yes" EndIf WEnd FileClose($Handle) If $c = 0 Then MsgBox(0, "Error", "No files/directories matched the requested time.") EDIT: I found out why, but i dont know how to fix it? The reason its not working is beacuse i got several lines called "ServicePackInEffect" and it only reads the first on. Can i create a loop in a loop? First loop for every file, and then loop for every ServicePackInEffect in that file, and stop if it gets the correct value? Edited December 10, 2004 by Doxie Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted December 10, 2004 Author Share Posted December 10, 2004 (edited) Lar, look at my last post above, you can see my edit. This is my new code, and its not working (of course) ;''Settings'' $folder = '\\eu2svr01\logfile$\Inventory\Stockholm\';-- With trailing backslash $filenames = '*.Log';-- Wildcards accepted. ;''Code'' $Handle = FileFindFirstFile($folder & $filenames) If $Handle = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf $c = 0 While 1 $file = $folder & FileFindNextFile($Handle) If @error Then ExitLoop ;------------------------------------------------ $d = 0 While 1 $time=IniRead($file,"Win32_QuickFixEngineering","ServicePackInEffect","") If @error Then ExitLoop $d = $d + 1 If $time = "KB889293-IE6SP1-20041111.235619" Then ExitLoop MsgBox(0, "Found", "Yes" & $file) WEnd ;------------------------------------------------ $c = $c + 1 WEnd FileClose($Handle) If $c = 0 Then MsgBox(0, "Error", "No files/directories matched the requested time.") Edited December 10, 2004 by Doxie Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted December 10, 2004 Author Share Posted December 10, 2004 Sorry, it did not actually fail... But it gave me the result of the first ServicePackInEffect and then continued to the next file. Instead of checking if the correct ServicePackInEffect was there. Example how the file look: ServicePackInEffect=KB835732 HotFixID=File 1 ServicePackInEffect=KB837001 HotFixID=File 1 ServicePackInEffect=KB839645 HotFixID=File 1 ServicePackInEffect=KB840315 HotFixID=File 1 ServicePackInEffect=KB840987 HotFixID=File 1 ServicePackInEffect=KB841356 HotFixID=File 1 ServicePackInEffect=KB841533 HotFixID=File 1 ServicePackInEffect=KB841873 And if i was looking for the last (KB841873) it stooped on the first one. Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
Doxie Posted December 10, 2004 Author Share Posted December 10, 2004 Should this work? $folder = '\\eu2svr01\logfile$\Inventory\Stockholm\';-- With trailing backslash $filenames = '*.Log';-- Wildcards accepted. ; Shows the filenames of all files in the current directory, note that "." and ".." are returned. $search = FileFindFirstFile($folder & $filenames) $Sstr = "KB889293-IE6SP1-20041111.235619" ; string to search ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr($file, $Sstr) Then MsgBox(4096, "File:", $file) ExitLoop EndIf Wend Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
SumTingWong Posted December 10, 2004 Share Posted December 10, 2004 Should this work?<{POST_SNAPBACK}>You are nearly there....here's what I wrote for you based on Larry's suggestion.Dim $hSearch, $sFolder, $sFile $sFolder = "\\eu2svr01\logfile$\Inventory\Stockholm\" $sFile = "*.LOG" $hSearch = FileFindFirstFile($sFolder & $sFile) If $hSearch > -1 Then While 1 $sFile = $sFolder & FileFindNextFile($hSearch) If @error Then ExitLoop $sFile = FileRead($sFile, FileGetSize($sFile)) If @error = 0 Then If StringInStr($sFile, "KB889293-IE6SP1-20041111.235619") Then ; patch found...do your thing!!! EndIf EndIf WEnd FileClose($hSearch) EndIfYou will still have to put your own code into the ; patch found...do your thing!!!block.Hope this helps. Link to comment Share on other sites More sharing options...
Doxie Posted December 10, 2004 Author Share Posted December 10, 2004 (edited) Thanks, it helped alot...Still only one small problem left It search and find the files, that has the patch value in it, now i try to read a string in the file it found, and use that string as file name.Look for yourself (it only give me empty results)Dim $hSearch, $sFolder, $sFile$sFolder = "\\eu2svr01\logfile$\Inventory\Stockholm\"$sFile = "*.LOG"$hSearch = FileFindFirstFile($sFolder & $sFile)If $hSearch > -1 Then While 1 $sFile = $sFolder & FileFindNextFile($hSearch) If @error Then ExitLoop $sFile = FileRead($sFile, FileGetSize($sFile)) If @error = 0 Then If StringInStr($sFile, "KB889293-IE6SP1-20041111.235619") Then $user = IniRead($sFile,"Win32_NetworkLoginProfile","UserAccount","") MsgBox(4096, "File:", $user) EndIf EndIf WEnd FileClose($hSearch)EndIf Edited December 10, 2004 by Doxie Were ever i lay my script is my home... Link to comment Share on other sites More sharing options...
SumTingWong Posted December 10, 2004 Share Posted December 10, 2004 Thanks, it helped alot...Still only one small problem left It search and find the files, that has the patch value in it, now i try to read a string in the file it found, and use that string as file name.Look for yourself (it only give me empty results)Dim $hSearch, $sFolder, $sFile$sFolder = "\\eu2svr01\logfile$\Inventory\Stockholm\"$sFile = "*.LOG"$hSearch = FileFindFirstFile($sFolder & $sFile)If $hSearch > -1 Then While 1 $sFile = $sFolder & FileFindNextFile($hSearch) If @error Then ExitLoop $sFile = FileRead($sFile, FileGetSize($sFile)) If @error = 0 Then If StringInStr($sFile, "KB889293-IE6SP1-20041111.235619") Then $user = IniRead($sFile,"Win32_NetworkLoginProfile","UserAccount","") MsgBox(4096, "File:", $user) EndIf EndIf WEnd FileClose($hSearch)EndIf<{POST_SNAPBACK}>I reused the $sFile var to store the content of the file found so $sFile is no longer the filename when you try to use it in IniRead.Here's the corrected version.Dim $hSearch, $sFolder, $sFile, $sData $sFolder = "\\eu2svr01\logfile$\Inventory\Stockholm\" $sFile = "*.LOG" $hSearch = FileFindFirstFile($sFolder & $sFile) If $hSearch > -1 Then While 1 $sFile = $sFolder & FileFindNextFile($hSearch) If @error Then ExitLoop $sData = FileRead($sFile, FileGetSize($sFile)) If @error = 0 Then If StringInStr($sData, "KB889293-IE6SP1-20041111.235619") Then $user = IniRead($sFile,"Win32_NetworkLoginProfile","UserAccount","") MsgBox(4096, "File:", $user) EndIf EndIf WEnd FileClose($hSearch) EndIf Link to comment Share on other sites More sharing options...
Doxie Posted December 13, 2004 Author Share Posted December 13, 2004 (edited) Hi, I just wanna thank you all for helping last week. I really apreciate it, Thanks. This is the final code i am using, and it works perfectly. Dim $hSearch, $sFolder, $sFile, $sData $file = FileOpen("Patch.xls", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, "Account" & @TAB & "Full Name" & @CRLF) $sFolder = "\\eu2svr01\logfile$\Inventory\Stockholm\" $sFile = "*.LOG" $hSearch = FileFindFirstFile($sFolder & $sFile) If $hSearch > -1 Then While 1 $sFile = $sFolder & FileFindNextFile($hSearch) If @error Then ExitLoop $sData = FileRead($sFile, FileGetSize($sFile)) If @error = 0 Then If StringInStr($sData, "KB889293-IE6SP1-20041111.235619") Then $user = IniRead($sFile,"Win32_NetworkLoginProfile","UserAccount","") $name = IniRead($sFile,"Win32_NetworkLoginProfile","FullName","") FileWrite($file, $user & @TAB & $name & @CRLF) ; IniWrite($user & ".txt", "Patchning", "Latest", "Yes") EndIf EndIf WEnd FileClose($file) FileClose($hSearch) EndIf Edited December 13, 2004 by Doxie Were ever i lay my script is my home... 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