Madix_t


Good day to the experts!

I have here below a VB Script i found in Script Center which is a very useful tool in reducing time to configure a static IP for each computers in a network, especially when you have more than 10 computers in a network.(NOTE: this computer's IP was configured manually with a purpose)

How could we convert this code into a VFP code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next

Thank you very much for any help regarding this matter





Re: how do i convert VB Script Code into a VFP Code?

dni


Somethig like this (not tested):

oWMIService = GetObject("winmgmts:")

var = oWMIService.colNetAdapters("Win32_NetworkAdapterConfiguration")

var.strIPAddress = Array("192.168.1.141")

.......







Re: how do i convert VB Script Code into a VFP Code?

dni

Example for ip addres:

Code Snippet

oWMIService = GetObject("winmgmts:")
var= oWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration", , 48)
for each objItem in var

objItem.IPAddress
next

You may find properties you need at:

http://msdn2.microsoft.com/en-us/library/aa394217.aspx







Re: how do i convert VB Script Code into a VFP Code?

Madix_t

what i i want to know is how to change the ip address of my local PC using vfp code...so i copy a VB script code if it is posible to convert this code into VFP code and how

thank you






Re: how do i convert VB Script Code into a VFP Code?

dni

Code Snippet

LOCAL oServer, oAdapters, oAdapter

oServer = GetObject("winmgmts:\\" + "." + "\root\cimv2")

oAdapters = oServer.ExecQuery(;

"SELECT * FROM Win32_NetworkAdapterConfiguration")

LOCAL cGateway

FOR EACH oAdapter IN oAdapters

WITH oAdapter

IF .IPEnabled

cGateway = IIF(ISNULL(.DefaultIPGateway), "",;

.DefaultIPGateway[0])

.IPAddress[0]

* change here, whatever you like

.IPAddress[0] = "100.100.100.100"

.IPAddress[0]

ENDIF

ENDWITH

NEXT






Re: how do i convert VB Script Code into a VFP Code?

Madix_t

thank you for your help dni, is there a way we can change the system ip and gateway in whatever ip and gateway we want, because in your example above, it only shows how but not to implement.

thank you for your help regarding this matter






Re: how do i convert VB Script Code into a VFP Code?

dni

I think you may have off DHCP and TCP/IP configuration for adapter turned on manually.