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

Re: Trying to implement a script? by Anders

Anders
Thu Apr 03 11:27:01 CDT 2008

STRCOMPUTER = "."
OBJWMISERVICE = Getobject("winmgmts:" ;
+ "{impersonationLevel=impersonate}!\\" + STRCOMPUTER + "\root\cimv2")

IPCONFIGSET = OBJWMISERVICE.EXECQUERY ;
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")

For Each IPCONFIG In IPCONFIGSET
If !Isnull(IPCONFIG.IPADDRESS) Then
For I=1 To Alen(IPCONFIG.IPADDRESS)-1
Messagebox("Address:" + IPCONFIG.IPADDRESS(I))
Endfor
Endif
Endfor

Does that help?
-Anders

"Linn Kubler" <lkubler@chartwellwisc2.com> wrote in message
news:uwTo5wYlIHA.484@TK2MSFTNGP04.phx.gbl...
> 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
>
>
>
>


Re: Trying to implement a script? by Linn

Linn
Fri Apr 04 15:09:20 CDT 2008

Yeah, that works. Funny how a little thing like -1 can make all the
difference. I also discovered that the IP Address is at index 0 of the
array. So I needed to start the For/Next loop at 0 not 1.

Thanks for the tip!
Linn

"Anders Altberg" <anders.altberg> wrote in message
news:%23GsiNealIHA.5396@TK2MSFTNGP04.phx.gbl...
> STRCOMPUTER = "."
> OBJWMISERVICE = Getobject("winmgmts:" ;
> + "{impersonationLevel=impersonate}!\\" + STRCOMPUTER + "\root\cimv2")
>
> IPCONFIGSET = OBJWMISERVICE.EXECQUERY ;
> ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
>
> For Each IPCONFIG In IPCONFIGSET
> If !Isnull(IPCONFIG.IPADDRESS) Then
> For I=1 To Alen(IPCONFIG.IPADDRESS)-1
> Messagebox("Address:" + IPCONFIG.IPADDRESS(I))
> Endfor
> Endif
> Endfor
>
> Does that help?
> -Anders
>
> "Linn Kubler" <lkubler@chartwellwisc2.com> wrote in message
> news:uwTo5wYlIHA.484@TK2MSFTNGP04.phx.gbl...
>> 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
>>
>>
>>
>>
>