willywill Posted October 14, 2009 Posted October 14, 2009 Hi all, I need to determine the hostname for the system post ghost install. The goal is to rename the computer description and hostname based on the steps below: 1. Run ipconfig (IP address served via DHCP MAC address reservation) 2. Copy the IP address 3. Search for the IP address in a text file located directly under C: 4. Once I find the IP address in the text file, then copy the hostname. The line contains this: 0.0.0.0 abc.group.com The list is going to have multiple IP addresses with hostsnames, and each machine will need to repeat the same step post ghost. Would this be the correct approach? Suggestions?
FuryCell Posted October 14, 2009 Posted October 14, 2009 (edited) You can use the macros @IPAddress1 and @ComputerName. There is also @IPAddress2,@IPAddress3,and @IPAddress4. For Example: MsgBox(0,"Test","Your computer name is: "& @ComputerName&@CRLF&"Your IP1 is: "&@IPAddress1) Edited October 14, 2009 by P5ych0Gigabyte HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.
willywill Posted October 15, 2009 Author Posted October 15, 2009 That macros help. I think the only remaining part is to search for the IP address in the list and match it to the hostname. any help there?
dantay9 Posted October 15, 2009 Posted October 15, 2009 FileOpen, FileReadLine in a loop, FileClose. Something like that. You could also use FileRead and split each line instead of filereadline. This would be a bit faster, but slightly more difficult.
willywill Posted October 15, 2009 Author Posted October 15, 2009 What I have so far: $file = FileOpen("C:\list.txt", 0) $IPAddress = String(@IPAddress1) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) Select Case @error = -1 MsgBox (0, "Search Result", "End Of File was met") ExitLoop Case StringInStr($line, @IPAddress1) MsgBox (0, "Search Result", $line) ExitLoop EndSelect WEnd FileClose($file) See anything I can improve on?
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