Jump to content

Displaying IPAddrses within HTA


geemail.email

Recommended Posts

Thanks in advance to whoever can assist.

I am launching an HTA after WinPE loads.

within the HTA, I am displaying, MAC addrses, DHCP Server IP address and Network Adapter IPAddress.

I get the MAC and DHCP IP with no problem. When I run the HTA locally on my workstation(XP SP2), I get the IP address as well. When I run the HTA after booting with the WINPE 2.0 cd, the IP Address displayed is the IPv6 address rather than the IPv4 address. Below is the code that runs to get and display the IP.

I would like to know how I can display either both IPAddresses or just the IPv4 address.

Thank you again, this forums continues to amaze me.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
n = 1
For Each objItem in colItems
If Not IsNull(objItem.IPAddress) Then
For i = 0 To UBound(objItem.IPAddress)
strDHCPIP = objItem.DHCPServer
strIPAddress = objItem.IPAddress(i)
Next
End If
n = n + 1
strHtml = objItem.MACAddress
strHtml_1 = objItem.DHCPServer

For Each strAddress in objItem.IPAddress
If strAddress = "0.0.0.0" Then
strHtml_2 = "<Font color = Red>" & "Cable Unplugged"
Else
strHtml_2 = strAddress
End If
Next
Next

Link to comment
Share on other sites


Couple of observations.

1 - You are looping through all adapters, fine if you only have one but otherwise it only returns data on the last adapter queried.

2 - Same issue with the IP addresses, with IPV4 & IPV6 both enabled in PE 2 the IPAddress field will contain more than one result but you are only ending up with the last value returned.

Edit:

If this is an HTA, you could append these values to the valueof a textbox or as added items in a listbox as you retrieve them instead of into a variable.

Link to comment
Share on other sites

IceManND...thank you for the reply....

First, I thought the addition of IPEnabled=True would narrow it to the adapter which is connected to the network. Is that wrong?

Since the posting, I have changed the code to the following:

strComputer = "."
Set objwmiService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objItem in colItems
If item.IPEnabled = True Then
strDHCPIP = objItem.DHCPServer
strIPAddress = objItem.IPAddress(0)

End If

I have not tried it in PE yet...working on rebuilding the iso a I read your reply. I understood the IPEnabled=True to mean if the adapter is enabled, then this would pull the active IP which I can then store as a variable and display on screen. I have been working on this for so many hours, I hate to now change the interface as I am learning and it takes me much longer than the average bear to rework the interface. However, if your recommendation is my only option to get it to work, then I must change it.

Thank you again for your reply....I also have followed your posted manual for the most part, with a few adjustments for my environment....when I finish with my version, I will pass along to everyone. Right now it is a mess of notes.

Does this

Link to comment
Share on other sites

no this is true you will only get the enabled adapters with IPEnabled=true.

What you have now should work assuming that the IPV4 address is always first. Not sure on that. But as a bonus with PE2 if you put the script into the WIM you can edit it when booted from the CD and test changes since the script resides in memory at that point. Then you don't have to rebuild everything until you know you have the script the way you want it and then save it to thumb drive or the local hard drive. I don't recall if notepad is in PE2 by default or not but you can throw the editor of your choice on and run that.

Link to comment
Share on other sites

Again, thank you for your expertise....it is invaluable. I have previously booted from the cd and then modified the script while in memory, but I began to wonder if that was a true test as you can tell my scripting techniques are limited and if I am storing things improperly into memory and then testing, it may not be valid.

One other quick question...do you use Ghost? I began my main HTA from the wizard.hta posted on this forum. I have modified slightly but not alot. One item I am having a problem with and have read posts referring to the same but have not gotten it to work is the launching of ghost32.exe with all the switches and also refers to the id of the radio button from which it was launched. When clicking the button, Ghost launches but I do not get the automated deploy of the image from the switches. In case you are familiar, the following is the code:

		strTaskValue =  Chr(34) & "z:\ghost11\ghost32.exe" & Chr(34) & " -clone,mode=restore,src=" & Chr(34) & Radio.Id & ".gho" & Chr(34) & ",dst=1"

I have also tried...

		strTaskValue =  "z:\ghost11\ghost32.exe -clone,mode=restore,src=" & Radio.Id & ".gho" & ",dst=1 -sure -FX"

Only ghost launches with either....I know it has something to do with the spacing and Chr34 but not sure how to troubleshoot it.

Thanks again Iceman...truly appreciated.

Link to comment
Share on other sites

I am far too familiar with Ghost, I was using it when it was still developed by Binary Research and I have the Ghost "beanie baby".

the way I check those values before sending the command s to echo the variable back to the screen using a msgbox

msgbox strTaskValue

Then you can verify you have all of the quotes correct in the string before it executes and if not you can work out where they should be.

Link to comment
Share on other sites

Again, your common sense far out weights my ability to think....i have done that a 1000X times and I don't know why I didn't think to do that while boot of the cd....that will help tremendously....

I have used Ghost for quite awhile as well, it is the mixture of Ghost and the scripting that is biting me in the @#%$.

I hope not to bother you any more today...I am gonna get the Ghost Button working if it takes me all weekend.

FYI...I am still getting the IPv6 address displayed in my hta, so for now, that will have to wait...it is only for informational purposes only to the person who will use the cd in case they are having issues, they can call me and I can ask them for the ip, dhcp server, etc..and it will be right in front of them.

Thanks again, and I hope you have a great weekend!

Moe

Link to comment
Share on other sites

quick update...not tested yet but most likely the cause...

For testing purposes, as to not begin deployment of the image during testing of buttons, I had routed the onclick call to execute ghost32.exe only....can anyone say BONEHEAD!..I am going to make that change and then I should be in business.

Link to comment
Share on other sites

This will give you IPv4 addresses:


For Each objItem in colItems
If Not IsNull(objItem.IPAddress) Then ' This adapter has an IP address
For Each valIPAddr in objItem.IPAddress
If InStr(valIPAddr,".") <> 0 Then ' If this is an IPv4 (#.#.#.#) address, not IPv6 (xx:xx:xx:xx...)
strIPAddress = valIPAddr
strDHCPIP = objItem.DHCPServer
End If
Next
End If
Next

Edited by WreX
Link to comment
Share on other sites

Wrex,

Thank you....before you sent your reply...this is what I came up with..

'Detect Network Settings 
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
If Not IsNull(objitem.IPAddress) Then
strIPAddress = objItem.IPAddress(0)
arrIPAddress = Split(strIPAddress, ".")

If arrIPAddress(0) = "192" Then
strDHCPIP = objItem.DHCPServer
strHtml = objItem.MACAddress
strHtml_1 = objItem.DHCPServer
strHtml_2 = strIPAddress
End If

If arrIPAddress(0) = "10" Then
strDHCPIP = objItem.DHCPServer
strHtml = objItem.MACAddress
strHtml_1 = objItem.DHCPServer
strHtml_2 = strIPAddress
End If

If arrIPAddress(0) = "0" Then
strHtml = objItem.MACAddress
strHtml_2 = "<Font color = Red>" & "Cable Unplugged"
End If
End If
Next

Since I am only concerned with IP beginning with 192 and 10, will this work or should I go with yours instead?

Thanks

Link to comment
Share on other sites

You don't need to check for IPs starting with 0 as a Network Adapter without an IP will have a Null value for objItem.IPAddress. Also, you wouldn't display any IP information if the address was not in the specified subnets, so why not just display it no matter what? Other than that, everything works fine.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...