sanhen Posted April 12, 2007 Share Posted April 12, 2007 (edited) expandcollapse popup#include <GUIConstants.au3> #include <GuiIPAddress.au3> $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For $objItem In $colItems $LocalGateway= $objItem.DefaultIPGateway(0) $LoaclHostName=$objItem.DNSHostName $LocalIP=$objItem.IPAddress(0) $LocalDns1= $objItem.DNSServerSearchOrder(0) $LocalDns2= $objItem.DNSServerSearchOrder(1) $LocalSubnetmask= $objItem.IPSubnet(0) $b=$objItem.Description Next $hgui = GUICreate("IP Address Control Create Example", 300, 300) $computername = GUICtrlCreateInput($LoaclHostName,150, 25, 80, 25) $IPAddress= _GUICtrlIpAddressCreate ($hgui, 10, 10, 125, 30,$WS_CHILD) _GUICtrlIpAddressSet ($IPAddress,$LocalIP) $Subnetmask = _GUICtrlIpAddressCreate ($hgui, 10, 50, 125, 30,$WS_CHILD) _GUICtrlIpAddressSet ($Subnetmask, $LocalSubnetmask) $Gateway = _GUICtrlIpAddressCreate ($hgui, 10, 90, 125, 30,$WS_CHILD) _GUICtrlIpAddressSet ($Gateway, $LocalGateway) $Dns1 = _GUICtrlIpAddressCreate ($hgui, 10, 130, 125, 30, $WS_CHILD) _GUICtrlIpAddressSet ($Dns1,$LocalDns1) $Dns2 = _GUICtrlIpAddressCreate ($hgui, 10, 170, 125, 30, $WS_CHILD) _GUICtrlIpAddressSet ($Dns2,$LocalDns2) $readbutton = GUICtrlCreateButton("read", 30, 250, 100, 25) $setbutton = GUICtrlCreateButton("Laws", 150, 250, 100, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $readbutton Case $msg = $setbutton Dim $SetIPAddress = _GUICtrlIpAddressGet ($IPAddress) Dim $SetSubnetmask = _GUICtrlIpAddressGet ($Subnetmask) Dim $SetGateway = _GUICtrlIpAddressGet ($Gateway) Dim $SetDns[2] $SetDns[0]=_GUICtrlIpAddressGet ($Dns1) $SetDns[1]=_GUICtrlIpAddressGet ($Dns2) $Setcomputername = GUICtrlRead($computername) ;MsgBox(64,"Information",$Setcomputername) For $objNetAdapter in $colComputers $objNetAdapter.Rename($Setcomputername) Next If IsObj($colItems) Then For $objNetAdapter in $colItems $objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask) $objNetAdapter.SetGateways($SetGateway) $objNetAdapter.SetDNSServerSearchOrder($SetDns) Next MsgBox(64,"Information ",$Setcomputername&@CRLF& $SetIPAddress _ &@CRLF& $SetSubnetmask&@CRLF&$SetGateway &@CRLF&$SetDns) EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Why amend the erroneous IP ??? Edited April 12, 2007 by sanhen Link to comment Share on other sites More sharing options...
ChrisL Posted April 12, 2007 Share Posted April 12, 2007 Whats the problem? It reports the first IP address on my system although I have several [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
sanhen Posted April 12, 2007 Author Share Posted April 12, 2007 IP Laws wrong. Link to comment Share on other sites More sharing options...
ChrisL Posted April 12, 2007 Share Posted April 12, 2007 IP Laws wrong.If you stop talking in riddles and explain exactly what is wrong you might get some help. [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
sanhen Posted April 12, 2007 Author Share Posted April 12, 2007 (edited) For $objNetAdapter in $colItems $objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask) $objNetAdapter.SetGateways($SetGateway) $objNetAdapter.SetDNSServerSearchOrder($SetDns) Why not amend the IP and DNS ï¼ Edited April 12, 2007 by sanhen Link to comment Share on other sites More sharing options...
ChrisL Posted April 13, 2007 Share Posted April 13, 2007 (edited) The IP address, Subnet etc need to be as arrays. I also put your WMI query in that part of the code too as it would not go through the For loop without. expandcollapse popup#include <GUIConstants.au3> #include <GuiIPAddress.au3> $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For $objItem In $colItems $LocalGateway= $objItem.DefaultIPGateway(0) $LoaclHostName=$objItem.DNSHostName $LocalIP=$objItem.IPAddress(0) $LocalDns1= $objItem.DNSServerSearchOrder(0) $LocalDns2= $objItem.DNSServerSearchOrder(1) $LocalSubnetmask= $objItem.IPSubnet(0) $b=$objItem.Description Next $hgui = GUICreate("IP Address Control Create Example", 300, 300) $computername = GUICtrlCreateInput($LoaclHostName,150, 25, 80, 25) $IPAddress= _GUICtrlIpAddressCreate ($hgui, 10, 10, 125, 30,$WS_CHILD) _GUICtrlIpAddressSet ($IPAddress,$LocalIP) $Subnetmask = _GUICtrlIpAddressCreate ($hgui, 10, 50, 125, 30,$WS_CHILD) _GUICtrlIpAddressSet ($Subnetmask, $LocalSubnetmask) $Gateway = _GUICtrlIpAddressCreate ($hgui, 10, 90, 125, 30,$WS_CHILD) _GUICtrlIpAddressSet ($Gateway, $LocalGateway) $Dns1 = _GUICtrlIpAddressCreate ($hgui, 10, 130, 125, 30, $WS_CHILD) _GUICtrlIpAddressSet ($Dns1,$LocalDns1) $Dns2 = _GUICtrlIpAddressCreate ($hgui, 10, 170, 125, 30, $WS_CHILD) _GUICtrlIpAddressSet ($Dns2,$LocalDns2) $readbutton = GUICtrlCreateButton("read", 30, 250, 100, 25) $setbutton = GUICtrlCreateButton("Laws", 150, 250, 100, 25) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $readbutton Case $msg = $setbutton Dim $SetIPAddress[1] $SetIPAddress[0] = _GUICtrlIpAddressGet ($IPAddress) Dim $SetSubnetmask[1] $SetSubnetmask[0] = _GUICtrlIpAddressGet ($Subnetmask) Dim $SetGateway[1] $SetGateway[0] = _GUICtrlIpAddressGet ($Gateway) ;Msgbox(0,"",$SetIPAddress[0] & " " & $SetSubnetmask[0] & " " & $SetGateway[0] ) Dim $SetDns[2] $SetDns[0]=_GUICtrlIpAddressGet ($Dns1) $SetDns[1]=_GUICtrlIpAddressGet ($Dns2) $Setcomputername = GUICtrlRead($computername) $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For $objNetAdapter in $colComputers $objNetAdapter.Rename($Setcomputername) Next If IsObj($colItems) Then For $objNetAdapter in $colItems $objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask) $objNetAdapter.SetGateways($SetGateway) $objNetAdapter.SetDNSServerSearchOrder($SetDns) Next MsgBox(64,"Information ",$Setcomputername&@CRLF& $SetIPAddress[0] _ &@CRLF& $SetSubnetmask[0]&@CRLF&$SetGateway[0] &@CRLF&$SetDns) EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Edited April 13, 2007 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
sanhen Posted April 14, 2007 Author Share Posted April 14, 2007 thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now