Hi,
I'm using VFP 9.0 sp1 and I'm trying include the functionallity of a script
I have. The script lists details about the network card in a computer.
Specifically I'm having trouble getting the IP address of the computer.
Here is the VBS script I'm trying to mimic:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.Caption & chr(13) & _
"MAC Address: " & IPConfig.MACAddress & chr(13) & _
"IP Address: " & IPConfig.IPAddress(i)
Next
End If
Next
And here is the code I came up with:
#DEFINE WbemAuthenticationLevelPktPrivacy 6
strUser = "domain\administrator"
strPassword = "domainadminpassword"
strComputer = "computername"
strNamespace = "root\cimv2"
objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
objWMIService = objwbemLocator.ConnectServer(strComputer, strNamespace,
strUser, strPassword)
objWMIService.Security_.authenticationLevel =
WbemAuthenticationLevelPktPrivacy
colNICSettings = objWMIService.ExecQuery ;
("SELECT * FROM Win32_NetworkAdapterConfiguration")
* ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
MESSAGEBOX(ALLTRIM(STR(colNICSettings.count)))
CREATE CURSOR NICSettings ;
(Index I, Caption C(65) NULL, Description c(55) NULL, DHCP_Server c(25)
NULL, ;
DNS_Domain c(25) NULL, DNS_Host_Name c(25) NULL, MAC_Address c(15) NULL, ;
IP_Address c(20) NULL)
FOR EACH objNIC IN colNICSettings
IF !ISNULL(objNic.IPAddress) THEN
FOR I = 1 TO ALEN(objNic.IPAddress)
strNICSettings = "Index: " + ALLTRIM(STR(objNic.Index)) + CHR(13) + ;
"Network Addresses: " + objNic.IPAddress(I)
NEXT
MESSAGEBOX(strNICSettings)
ENDIF
NEXT
BROWSE
MESSAGEBOX("Done!")
When I run this program it totally crashes VFP. Any ideas what I might be
doing wrong here? Can this be done?
Here is a link to the win32_networkadapterconfiguration class, which
describes the IPAddress property as a string array.
http://msdn2.microsoft.com/en-us/library/aa394217(VS.85).aspx
Thanks in advance,
Linn