Hey, here is what i need :
The script check if i am in DHCP, it disable it, and enable static ip ( i give it the right ip adress in the script ), and if im not, he enable dhcp.
so : if dhcp -> static ip
If static ip -> Dhcp
Here is the beginning of my code.
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\reseau.txt", True)
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("ipconfig /all")
strIpConfig = objScriptExec.StdOut.Readall
myfile.WriteLine (strIpConfig)
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
Set MyFile = fs
penTextFile("c:\reseau.txt", ForReading)
ReadLineTextFile = MyFile.ReadLine
teststr = myfile.readline
if instr(teststr, "DCHP activ") > non then
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
next
Else
strIPAddress = Array("192.168.0.3")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.1")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(_
strGateway, strGatewaymetric)
next
end if
myfile.close
But its not working
I dont want to check by line number, because the result of ipconfig /all change if dhcp is enable, so the "check line" is not the same.
The value " DHCP activ " is the result in my .txt of the ipconfig /all
Adapter
Adresse physique. . . . . . . . . : *******
DHCP activ‚ . . . . . . . . . . . : Non
Adresse IP. . . . . . . . . . . . : 192.168.0.3
Masque de sous-r‚seau . . . . . . : 255.255.255.0
Passerelle par d‚faut . . . . . . : 192.168.0.1
Any idea ?
The script check if i am in DHCP, it disable it, and enable static ip ( i give it the right ip adress in the script ), and if im not, he enable dhcp.
so : if dhcp -> static ip
If static ip -> Dhcp
Here is the beginning of my code.
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\reseau.txt", True)
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec("ipconfig /all")
strIpConfig = objScriptExec.StdOut.Readall
myfile.WriteLine (strIpConfig)
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
Set MyFile = fs
ReadLineTextFile = MyFile.ReadLine
teststr = myfile.readline
if instr(teststr, "DCHP activ") > non then
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
next
Else
strIPAddress = Array("192.168.0.3")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.1")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic( _
strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(_
strGateway, strGatewaymetric)
next
end if
myfile.close
But its not working
The value " DHCP activ " is the result in my .txt of the ipconfig /all
Adapter
Adresse physique. . . . . . . . . : *******
DHCP activ‚ . . . . . . . . . . . : Non
Adresse IP. . . . . . . . . . . . : 192.168.0.3
Masque de sous-r‚seau . . . . . . : 255.255.255.0
Passerelle par d‚faut . . . . . . : 192.168.0.1
Any idea ?