Sign in to follow this  
Followers 0
sanhen

wmi error

7 posts in this topic

#1 ·  Posted (edited)

#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 by sanhen

Share this post


Link to post
Share on other sites

IP Laws wrong.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For $objNetAdapter in $colItems

$objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask)

$objNetAdapter.SetGateways($SetGateway)

$objNetAdapter.SetDNSServerSearchOrder($SetDns)

Why not amend the IP and DNS ï¼

Edited by sanhen

Share this post


Link to post
Share on other sites

#6 ·  Posted (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.

#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 by ChrisL

Share this post


Link to post
Share on other sites

thanks

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0