Thinkster Posted July 21, 2005 Posted July 21, 2005 I have been trying to figure out a way to do this 25 machine deployment and I've resorted to using an Install Product key for the installation, running some post installation stuff, then running SysPrep. I know you can pre-fill Machine name and Product Key in the sysprep.inf, but I need to have one of my post installations bat files run a script that will Retrieve the current machines UUID or even MAC ID, look that up in a database (in the Sysprep Directory of current machine) and then modify (add) the appropriate Machine name & Prodcut key entries in the sysprep.inf file. After my post installation reboot, I then want it to run Sysprep and that should take care of it..Unfortunately I don't know enough on scripting to do this. I'm more of a .cmd/.bat person
Nilfred Posted July 22, 2005 Posted July 22, 2005 I didn't understand completelly, but I get this conclusion:UUID varies across same computer, unreliable.ipconfig /all gave MAC Adress from machine NIC.A database consisting of sysprep.inf files on subdirectories like XX-XX-XX-XX-XX-XX\sysprep.infOne subdir per MAC addressIf the media is writeable the database may consist of 25 [MAC HERE].inf files and rename the coincident to sysprep.infI'm unaware of sysprep flow but have good batch skills, for help you further let me know, step by step, what you did manually.
Martin Zugec Posted July 22, 2005 Posted July 22, 2005 Hold on... I found myself unsusable with this task (.net ), however I am talking with one friend right now about this. It should be more universal utility:GetVar.exeSearch.txtmac, ip, pcname, username-------------------------------------000BDB8743BE,172.16.1.38,pc1,mzugecNow you will be able to use getvar with following syntax:GetVar -set mac=000BDB8743BE -get username, pcnameIt will create two variables:getvarUsername = mzugecgetvarPCName = pc1
Thinkster Posted July 22, 2005 Author Posted July 22, 2005 Actually, username "companyuser" stays the same on each machine. What I want to do is before sysprep is ran, to have the appropriate sysprep.inf file in place. By appropriate, I mean that each machine has it's own unique MAC ID and UUID and each machine has a Product Key Sticker. So the database would be like:000BDB8743BE,Machine-05,1234-XXXX-5678-XXXXX-91011000BC56EFA01,Machine-09,5555-XXXX-66666-77777-XXXX (MAC ID, Machine name, Product key) The script would query the machine's MAC ID or UUID (doesn't matter to me), look that up in the database and either modify entries in sysprep.inf or copy 1 of 25 different sysprep.inf files to the sysprep folder. I am not concerned with username as that I have hardcoded in winlogon.
Martin Zugec Posted July 22, 2005 Posted July 22, 2005 Well, if you look at the syntax, you will see that it is universal. It is taking first line as identifiers what are the names of values (he dont care about them in any way)... He agreed, I will let you know when the program is ready
Thinkster Posted July 25, 2005 Author Posted July 25, 2005 Well, I was able to come up with the second half myself using the following code:@ECHO OFFTITLE Sysprep CustomizerSET C1=GATEWAY-06SET P1=12345-ABCDE-12345-ABCDE-12345ECHO.ECHO Editing Sysprep.infECHO.SET T1=Fedit -add -once -f Sysprep.inf -s UserData%T1% ComputerName=%C1%%T1% ProductKey=%P1%ECHO [userData] section completed...EXITI'm using the Fedit utility I found in BTS Driver Pack. Of course in this example, the variable C1 & P1 are hard coded. Ultimately %C1% should be a variable pulled from the database as well as %P1%. I don't know a command line way of pulling the current PC's MAC ID into a variable. IPCONFIG /ALL tells me the MAC ID as well as a bunch of other info, but I don't know how that can be usefull in the whole scheme of this..
Thinkster Posted July 25, 2005 Author Posted July 25, 2005 No I don't have to do it from DOS, as it would be running from within the Windows environment (during RunOnce). I just discovered also, that I actually can make use of IPCONFIG /ALL by using: IPCONIFG /ALL >C:\Sysprep\netdata.txt which outputs the information to the text file netdata.txt which happens to contain the 'Physical Address' (MAC ID). Now, a nice little script Possible usage of this one should be able to extract just the MAC ID from that text file and store it in a variable. Then lookup that variable for a match in the "database".BTW, the NIC's on all these machines are Marvell Yukon and all start with a MAC ID: 00 E0 B8 80 XX XX, so I may only be interested in looking at the last two bytes.So possible database format: (Last two bytes of Mac ID, Machine Name, Product Key) 58-DB,Gateway-06,12345-67890-AABBC-DDEEF-00000 57-15,Gateway-05,00000-11111-AAAAA-12345-889B, and so on....
Martin Zugec Posted July 25, 2005 Posted July 25, 2005 Oh, in that case it is quite simple... give me few minutes, I will write that script for you...
Martin Zugec Posted July 25, 2005 Posted July 25, 2005 Mac.batfor /f "usebackq delims=," %%i IN (`getmac /fo csv /nh`) do ( For /f "usebackq delims=, tokens=1,2" %%a IN (`type mac.txt`) DO If %%i EQU %%a Set strComputername=%%b)Echo %strComputername%Mac.txt"00-0B-DB-87-43-BE",pc1"00-0B-DB-87-43-BF",pc2"00-0B-DB-87-43-BD",pc3
jachin Posted July 25, 2005 Posted July 25, 2005 Try this...GetMAC.vbsOn Error Resume NextConst wbemFlagReturnImmediately = &h10Const wbemFlagForwardOnly = &h20Const ForReading = 1Dim fsDim shDim nwDim strMAC, strComp, strPIDSet sh = CreateObject("WScript.Shell")Set fs = CreateObject("Scripting.FileSystemObject")Set nw = CreateObject("WScript.Network")strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter " _ & "Where NetConnectionID = " & _ "'Local Area Connection'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)For Each objItem in colItems strMACAddress = objItem.MACAddressNext'Open our text file and get the machine detailsSet objFile = fs.OpenTextFile("Machines.txt", ForReading, false)Do While objFile.AtEndOfStream <> True If inStr(objFile.ReadLine, strMACAddress) Then colDetails = Split(objFile.ReadLine, ",") writeini "sysprep.ini", "UserData", "ComputerName", colDetails(1) writeini "sysprep.ini", "UserData", "ProductKey", colDetails(2) Else objFile.Skipline End IfLoopobjFile.Close' READINI ( file, section, item )' file = path and name of ini file' section = [Section] must not be in brackets' item = the variable to readFunction ReadIni(file, section, item) ReadIni = "" file = Trim(file) item = Trim(item) Set ini = fs.OpenTextFile( file, 1, False) Do While ini.AtEndOfStream = False line = ini.ReadLine line = Trim(line) If LCase(line) = "[" & LCase(section) & "]" Then line = ini.ReadLine line = Trim(line) Do While Left( line, 1) <> "[" 'If InStr( 1, line, item & "=", 1) = 1 Then equalpos = InStr(1, line, "=", 1 ) If equalpos > 0 Then leftstring = Left(line, equalpos - 1 ) leftstring = Trim(leftstring) If LCase(leftstring) = LCase(item) Then ReadIni = Mid( line, equalpos + 1 ) ReadIni = Trim(ReadIni) Exit Do End If End If If ini.AtEndOfStream Then Exit Do line = ini.ReadLine line = Trim(line) Loop Exit Do End If Loop ini.CloseEnd Function' WRITEINI ( file, section, item, myvalue )' file = path and name of ini file' section = [Section] must not be in brackets' item = the variable to write;' myvalue = the myvalue to assign to the item.'Sub WriteIni( file, section, item, myvalue ) in_section = False section_exists = False item_exists = ( ReadIni( file, section, item ) <> "" ) wrote = False file = Trim(file) itemtrimmed = Trim(item) myvalue = Trim(myvalue) temp_ini = sh.ExpandEnvironmentStrings("%TEMP%\") & fs.GetTempName Set read_ini = fs.OpenTextFile( file, 1, True, TristateFalse ) Set write_ini = fs.CreateTextFile( temp_ini, False) While read_ini.AtEndOfStream = False line = read_ini.ReadLine linetrimmed = Trim(line) If wrote = False Then If LCase(line) = "[" & LCase(section) & "]" Then section_exists = True in_section = True ElseIf InStr( line, "[" ) = 1 Then in_section = False End If End If If in_section Then If item_exists = False Then write_ini.WriteLine line write_ini.WriteLine item & "=" & myvalue wrote = True in_section = False Else equalpos = InStr(1, line, "=", 1 ) If equalpos > 0 Then leftstring = Left(line, equalpos - 1 ) leftstring = Trim(leftstring) If LCase(leftstring) = LCase(item) Then write_ini.WriteLine itemtrimmed & "=" & myvalue wrote = True in_section = False End If End If If Not wrote Then write_ini.WriteLine line End If End If Else write_ini.WriteLine line End If Wend If section_exists = False Then ' section doesn't exist write_ini.WriteLine write_ini.WriteLine "[" & section & "]" write_ini.WriteLine itemtrimmed & "=" & myvalue End If read_ini.Close write_ini.Close If fs.FileExists(file) then fs.DeleteFile file, True End if fs.CopyFile temp_ini, file, true fs.DeleteFile temp_ini, TrueEnd SubThe Machines.txt looks like this:Machines.txt00:0F:1F:B4:88:EF,Machine-09,5555-XXXX-66666-77777-XXXX00:0F:1F:B4:88:E8,Machine-04,5555-XXXX-66666-77777-XXXX
Thinkster Posted July 25, 2005 Author Posted July 25, 2005 Mac.batfor /f "usebackq delims=," %%i IN (`getmac /fo csv /nh`) do ( For /f "usebackq delims=, tokens=1,2" %%a IN (`type mac.txt`) DO If %%i EQU %%a Set strComputername=%%b)Echo %strComputername%Mac.txt"00-0B-DB-87-43-BE",pc1"00-0B-DB-87-43-BF",pc2"00-0B-DB-87-43-BD",pc3<{POST_SNAPBACK}>Wow Thank you Martin, I didn't know it could be done with just a few lines! That's great, but how can I expand that to also include Product Key and store that as %ProdKey% ? Here is a snipit of my Mac.txt file:"00-0B-DB-87-43-BE",Gateway-01,11111-XXYXX-66666-77777-XXXUX"00-0B-DB-87-43-BF",Gateway-02,55555-XXTXX-66666-77777-XXXTX"00-0B-DB-87-43-BD",Gateway-03,11223-56789-00111-555AB-TKETK"00-11-2F-C9-D8-30",Gateway-04,ABC12-MSPRO-XXXXX-USR55-KPWR1
Nilfred Posted July 26, 2005 Posted July 26, 2005 (edited) mac.bat@ECHO OFFREM Skip Sub(s)GOTO :StartREM Found Sub:FoundSET strComputerName=%1SET strProductKey=%2GOTO :EOF:StartFOR /f "usebackq delims=," %%i IN (`getmac /fo csv /nh`) DO ( FOR /f "usebackq delims=, tokens=1,2,3" %%a IN (`type mac.txt`) DO IF %%i EQU %%a CALL :Found %%b %%c)ECHO %strComputername% %strSerial%mac.txt"00-0B-DB-87-XX-XX",Gateway-01,11111-XXYXX-66666-77777-XXXUX"00-0B-DB-87-XX-XX",Gateway-02,55555-XXTXX-66666-77777-XXXTX"00-0B-DB-87-XX-XX",Gateway-03,11223-56789-00111-555AB-TKETK"00-11-2F-C9-XX-XX",Gateway-04,ABC12-MSPRO-XXXXX-USR55-KPWR1Note to the n00b unaware of what is going on: Add your own MAC addresss anywhere into mac.txt for testing purposes Edited July 26, 2005 by Nilfred
Martin Zugec Posted July 26, 2005 Posted July 26, 2005 for /f "usebackq delims=," %%i IN (`getmac /fo csv /nh`) do ( For /f "usebackq delims=, tokens=1-3" %%a IN (`type mac.txt`) DO If %%i EQU %%a ( Set strComputername=%%b Set strProduct=%%c ))
Thinkster Posted July 26, 2005 Author Posted July 26, 2005 OK, Got it to work! Thank you both!Now quick question, does this script have any dependencies as I tried running it on my friends laptop (added his MAC ID & PC Name, ProdKey to database) and it complained about 'getmac' saying that it wasn't an internal or external command or something like that.. Also, the laptop was XP Home in case that matters...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now