Hi dansherman, did you ever solve this?
I'm looking for a way to do this as well and tried WMI, which gives me the same garbled result as you get/ got and also tried RegRead.
Regread works on my machine and other Windows 7, DHCP enabled machines but not on XP or Vista or when the IP is manually set..
My WMI code:
Code:
COM_Init()
WMI_Query("\\.\root\cimv2", "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "IPAddress")
ItemIP := WMI_Query("\\.\root\cimv2", "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "IPAddress")
FileAppend, %ItemIP%, NetworkX.txt
COM_Term()
ExitApp
WMI_Query(Namespace, Class, Property = "")
{
psvc := COM_GetObject("winmgmts:{impersonationLevel=impersonate}!" . Namespace)
pset := COM_Invoke(psvc, "ExecQuery", "SELECT * FROM " . Class)
penm := COM_Invoke(pset, "_NewEnum")
Loop, % COM_Invoke(pset, "Count")
If COM_Enumerate(penm,pobj)=0
{
If Not Property
MsgBox % COM_Invoke(pobj, "GetObjectText_")
Else sResult.=COM_Invoke(pobj, Property) . "`n"
COM_Release(pobj)
}
COM_Release(penm)
COM_Release(pset)
COM_Release(psvc)
Return sResult
}
and another flavor of WMI:
Code:
COM_Init()
OpenEvent := "NetworkConfig.txt"
wLine := " +----------------- [Network Configuration] -----------------+ "
wLineBlank := " "
oFSO := COM_CreateObject("Scripting.FileSystemObject")
oNetworkConfig := COM_Invoke(oFSO,"CreateTextFile",OpenEvent, True)
COM_Invoke(oNetworkConfig,"WriteLine",wLine)
COM_Invoke(oNetworkConfig,"WriteLine",wLineBlank)
NameSpace := "root\CIMV2"
Class := "Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"
Query := "SELECT * FROM " . Class
objWMIService := COM_GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\" . Namespace)
colItems := COM_Invoke(objWMIService, "ExecQuery", Query)
enum := COM_Invoke(colItems, "_NewEnum")
while (COM_Enumerate(enum, objItem) = 0)
;For Each objItem in colItems
{
ItemIP := COM_Invoke(objItem, "IPAddress")
MsgBox %ItemIP%
ItemSubnet := COM_Invoke(objItem, "IPSubnet")
ItemGateway := COM_Invoke(objItem, "DefaultIPGateway")
ItemMAC := Com_Invoke(objItem, "MACAddress")
ItemDescription := COM_Invoke(objItem, "Description")
ItemDHCPEnabled := COM_Invoke(objItem, "DHCPEnabled")
}
COM_Invoke(oNetworkConfig,"WriteLine", ItemDescription) . "`n" . A_Tab
COM_Invoke(oNetworkConfig,"WriteLine"," IP Address :" ItemIP). "`n" . A_Tab
COM_Invoke(oNetworkConfig,"WriteLine"," Subnet Mask : " ItemSubnet). "`n" . A_Tab
COM_Invoke(oNetworkConfig,"WriteLine"," Default Gateway : " ItemGateway). "`n" . A_Tab
COM_Invoke(oNetworkConfig,"WriteLine"," MAC Address : " ItemMAC). "`n" . A_Tab
COM_Invoke(oNetworkConfig,"WriteLine", " DHCP Enabled : " ItemDHCPEnabled). A_Tab . "`n" . "`n"
COM_Release(objWMIService), objWMIService := 0
COM_Release(colItems), colItems :=
COM_Release(oNetworkConfig), oNetworkConfig :=
COM_Term()
Result of this one is, on my machine:
Quote:
+----------------- [Network Configuration] -----------------+
Intel(R) Wireless WiFi Link 4965AGN
IP Address :11047464
Subnet Mask : 11047512
Default Gateway : 11047608
MAC Address : 00:1D:E0:6F:B9:6D
DHCP Enabled : -1
I took these snippets from examples on this forum, I don't remember who posted it but thanks!
The problem is that the output of the WMI Query of the IP Address is
Quote:
{"192.168.1.101","fe80::e54f:44fc:874e:d93e"}
and I'm guessing that's what gives me this result just as you describe.. I did read on MSDN that the output of IPAddress is a String Array but I've dealt with those before and they never gave me this issues, those values werent numerical but names of drives (e.g. ST3500341AS)
Does anyone know how to best solve this?
Also, the Description of the 'IPEnabled' adapter is perfect and I can use that to search the registry:
Code:
Loop, HKEY_LOCAL_MACHINE, Software\Microsoft\Windows%A_Space%NT\CurrentVersion\NetworkCards, 1, 1
{
if a_LoopRegType = key
value =
else
{
RegRead, value
if ErrorLevel
value = *error*
If value = %ItemDescription%
{
Loop, %A_LoopRegKey%, %A_LoopRegSubKey%, 1, 1
if a_LoopRegType = key
{
servicename =
}
else
{
RegRead, servicename
if ErrorLevel
servicename = *error*
}
If servicename != %ItemDescription%
{
RegRead , ItemIP, HKLM, System\CurrentControlSet\Services\TCPIP\Parameters\Interfaces\%servicename%, DHCPIPAddress
RegRead , ItemSubnet, HKLM, System\CurrentControlSet\Services\TCPIP\Parameters\Interfaces\%servicename%, DHCPSubnetMask
RegRead , ItemGateway, HKLM, System\CurrentControlSet\Services\TCPIP\Parameters\Interfaces\%servicename%, DHCPDefaultGateway
RegRead , ItemDHCPEnabled, HKLM, System\CurrentControlSet\Services\TCPIP\Parameters\Interfaces\%servicename%, EnableDHCP
If ItemDHCPEnabled = 1
ItemDHCPEnabled = True
}
}
}
}
Again, this works on my machine but not on others, I know there are other variables when the machine isn't configured via DHCP but even when I build in a check for DHCPEnabled and then search for different variables I still don't get the correct results, at least on XP..
I'm using this in a system info gathering tool we use to evaluate customer's systems and it would be nice if I could get it to work.. I don't know what'll happen in either of these examples when multiple network adapters are IPEnabled though so if someone even knows how to do that I'd be very grateful!
Thanks for taking a look!