Mason Posted June 13, 2005 Share Posted June 13, 2005 hi guys,i have a lill problem at work. i need to deploy a script to 1000 clients which puts the computername into the bios.therefor i found a bios utility for the hp machines we use that writes the bios values to a txt file ... now i just have to search and replace the the right line in the file ....as i have not much expirience with vb maybe some of you guys can help ... i managed to cutnpaste some script that does the trick .... but it has a lill flaw .. look :thats a part of the bios txt i have :.....Cache Size (L1/L2) 20/128 KBMemory Size 512 MBSystem BIOS 786B2 v1.10Chassis Serial Number FRB34702RSAsset Tracking Number FRB34702RSRemovable Media Boot *Enable Disable....the field i need to change is the 'asset tracking number' ... my scripts read the bios values via wmi and make a search / change for each line in the file ....to bad that on new machines the serial number and the asset tag are the same ... so it changes both values ...maybe some1 can give me a hint in the right direction ?heres the script i dirty cutnpasted strComputer = "."Set WshNetwork = WScript.CreateObject("WScript.Network")Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colSMBIOS = objWMIService.ExecQuery _ ("SELECT * FROM Win32_SystemEnclosure")For Each objSMBIOS in colSMBIOS Set fso = CreateObject("Scripting.FileSystemObject") SourceFile="bios.cur" DestFile="bios.new" Set MyFile = fso.OpenTextFile(SourceFile, 1) Set NewFile = fso.OpenTextFile(DestFile, 2,True) do while MyFile.AtEndOfStream <> True Zeile = MyFile.ReadLine wrtstrg=Replace(Zeile, objSMBIOS.SMBIOSAssetTag, WshNetwork.ComputerName) NewFile.WriteLine wrtStrg loopNextthx a lot for your attention mason Link to comment Share on other sites More sharing options...
ack-hh Posted June 13, 2005 Share Posted June 13, 2005 (edited) strComputer = "."Set WshNetwork = WScript.CreateObject("WScript.Network")Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colSMBIOS = objWMIService.ExecQuery _ ("SELECT * FROM Win32_SystemEnclosure")For Each objSMBIOS in colSMBIOS Set fso = CreateObject("Scripting.FileSystemObject") SourceFile="bios.cur" DestFile="bios.new" Set MyFile = fso.OpenTextFile(SourceFile, 1) Set NewFile = fso.OpenTextFile(DestFile, 2,True) status = 0 do while MyFile.AtEndOfStream <> True Zeile = MyFile.ReadLine Select Case vbTrue Case InStr(UCase(Zeile), "ASSET TRACKING NUMBER") <> 0 status = 1 Case status = 1 wrtstrg=Replace(Zeile, objSMBIOS.SMBIOSAssetTag, WshNetwork.ComputerName) status = 0 End Select NewFile.WriteLine wrtStrg loopNextWhen a line containing "asset tracking number" is found,status changes from "0" to "1", thus indicating the NEXTline has to be modified. After mod has taken place, statusgets reset, so no other line will be changed.HTH Andreas Edited June 13, 2005 by ack-hh Link to comment Share on other sites More sharing options...
Mason Posted June 16, 2005 Author Share Posted June 16, 2005 hey ack-hh ... thx a lot for your effort ... highly appreciated but when i use your code ... it produces a new file just with the asset number in a row ...ill attach the original file and the file your script generated ... maybe you can have another look? would be great .... thx bud!bios.zip Link to comment Share on other sites More sharing options...
Mason Posted June 16, 2005 Author Share Posted June 16, 2005 hmm with my limited scripting skills ... maybe you missed the For Each objSMBIOS in colSMBIOS loop ? could that be ? that would imho explain the output .... Link to comment Share on other sites More sharing options...
dman Posted June 16, 2005 Share Posted June 16, 2005 (edited) At quick glance it just looks like the "normal" condition was omitted. Maybe something like this... If it finds the "ASSET" tag it echos the line to output file, reads the next line and writes the replacement. If the tag is not found it just echos the current line.do while MyFile.AtEndOfStream <> True Zeile = MyFile.ReadLine if InStr(UCase(Zeile), "ASSET TRACKING NUMBER") <> 0 then NewFile.WriteLine zeile Zeile = MyFile.ReadLine NewFile.WriteLine Replace(Zeile, objSMBIOS.SMBIOSAssetTag, WshNetwork.ComputerName) else NewFile.WriteLine zeile end ifloopand really, you don't even have to worry about the replace() function since you are just swapping one line for another. It could just bedo while MyFile.AtEndOfStream <> True Zeile = MyFile.ReadLine if InStr(UCase(Zeile), "ASSET TRACKING NUMBER") <> 0 then NewFile.WriteLine zeile Zeile = MyFile.ReadLine NewFile.WriteLine WshNetwork.ComputerName else NewFile.WriteLine zeile end ifloop Edited June 16, 2005 by dman Link to comment Share on other sites More sharing options...
Mason Posted June 17, 2005 Author Share Posted June 17, 2005 thx a lot ... managed to get it working that way 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