slartie Posted July 17, 2012 Share Posted July 17, 2012 I have a script that gathers BIOS and registry information for the PC's in my company network, writes the information to a text file. Now I'd like to expand the script, so it maintains the list of records, but updates a line of information with new data if that happens to be the case. In this case I'd like to update the records to reflect that a new user is using a given machine. I've found _FileWriteToLine which would seem to be the way to go, but it's been a bit too long since I last messed with AutoIt, so I'm actually not sure how to go about it. Any help/tips would be greatly appreciated. expandcollapse popup$servicetag = "" $manufacturer = "" $cpuspeed = "" $cpu = "" $model = "" $modeldell = "" servicetag() registryinfo() writemachineinfo() Func servicetag() $objshell = ObjCreate("WScript.Shell") $objfs = ObjCreate("Scripting.FileSystemObject") $strcomputer = "." $owmi = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strcomputer & "\root\cimv2") $colsmbios = $owmi.execquery("Select * from Win32_SystemEnclosure") For $objsmbios In $colsmbios $servicetag = $objsmbios.serialnumber $manufacturer = $objsmbios.manufacturer Next EndFunc Func registryinfo() $cpuspeed = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "~MHz") $cpu = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", "ProcessorNameString") $model = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "SystemFamily") $modeldell = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "SystemProductName") EndFunc Func writemachineinfo() $filetoopen = FileOpen("\\srv11\MachineInfo\records.txt", 0) $textfilename = FileRead($filetoopen) FileClose($filetoopen) $texttofile = @ComputerName & "," & @UserName & "," & $servicetag & "," & $manufacturer & "," & $model & "," & $modeldell & "," & @OSVersion & "," & $cpu & @CRLF If StringInStr($textfilename, @ComputerName, 0) Then Else $filetoopen = FileOpen("\\srv11\MachineInfo\records.txt", 2) $temp = $textfilename & $texttofile FileWrite($filetoopen, $temp) FileClose($filetoopen) EndIf EndFunc Link to comment Share on other sites More sharing options...
PhoenixXL Posted July 17, 2012 Share Posted July 17, 2012 i think u should try Ini's using them if the keyname is the same then the data of the key is overwritten This should be the simplest way [ in accordance to me] Try IniWrite and IniRead in place of FileWrite and FileRead respectively Regards Phoenix XL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
slartie Posted July 17, 2012 Author Share Posted July 17, 2012 While I can see how the .Ini approach would work, it would make the records a slight nightmare to import into a database elsewhere. So for now I'll have to find a way to manipulate the records.txt file "as is" rather than changing the format. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 17, 2012 Moderators Share Posted July 17, 2012 While I can see how the .Ini approach would work, it would make the records a slight nightmare to import into a database elsewhere.So why not look into AutoIt's SQLite options in the help file, and use a database to begin with? Then you won't have to worry about correctly importing from a flat text file later on "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
slartie Posted July 18, 2012 Author Share Posted July 18, 2012 So why not look into AutoIt's SQLite options in the help file, and use a database to begin with? Then you won't have to worry about correctly importing from a flat text file later on Now there's something I didn't know about. I'll be looking into that immediately!Thanks for the heads up! 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