Jump to content
Sign in to follow this  
tempman

Refreshig script

Recommended Posts

tempman

This script read ipconfig but only once

#NoTrayIcon
#include <GuiConstants.au3>

GuiCreate("IPset", 400, 400)

GuiCtrlCreateTab(5, 5, 390, 350)
GuiCtrlCreateTabItem("IP address")
#Region
$ip = Run(@ComSpec & " /c ipconfig","",@SW_HIDE, 2)
$ip_output=StdoutRead($ip)
GUICtrlCreateLabel ($ip_output, 80, 50, 0, 0)
#EndRegion

GuiSetState()

While 1
    $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd

GUIDelete()
Exit

How to refresh script after seting another IP without restarting?

Share this post


Link to post
Share on other sites
monoceres

This script read ipconfig but only once

How to refresh script after seting another IP without restarting?

Do you mean that the label will be updated? Then GUICtrlSetData() will do fine, I added it to your script, so now F2 refresh it.

#NoTrayIcon
#include <GuiConstants.au3>
GuiCreate("IPset", 400, 400)
GuiCtrlCreateTab(5, 5, 390, 350)
GuiCtrlCreateTabItem("IP address")
#Region
$ip = Run(@ComSpec & " /c ipconfig","",@SW_HIDE, 2)
$ip_output=StdoutRead($ip)
$label=GUICtrlCreateLabel ($ip_output, 80, 50, 0, 0) ; Added control id
HotKeySet("{F2}","_refresh") ; add hotkey
#EndRegion

GuiSetState()

While 1
    $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd

GUIDelete()
Exit

Func _refresh() ; Function that will be executed when pressing F2
    $ip = Run(@ComSpec & " /c ipconfig","",@SW_HIDE, 2)
    $ip_output=StdoutRead($ip)
    GUICtrlSetData($label,$ip)
EndFunc

Hope it helped :)

Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
tempman

I try these and don`t work.

When I change IP adress and press F2, in script i get some numbers...

Edited by tempman

Share this post


Link to post
Share on other sites
monoceres

I try these and don`t work.

When I change IP adress and press F2, in script i get some numbers...

Why don't you just use @IpAddress1 or _GetIP()?

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
tempman

Why don't you just use @IpAddress1 or _GetIP()?

Couse I nead IP, Subnetmask and Gateway to be display... :)

Share this post


Link to post
Share on other sites
monoceres

Couse I nead IP, Subnetmask and Gateway to be display... :)

Did it work before pressing F2?

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
monoceres

Ooops now I see the error :)

Please change $ip to $ip_output in GUICtrlSetData :(


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Info

Ooops now I see the error :)

Please change $ip to $ip_output in GUICtrlSetData :(

Lol :D

Share this post


Link to post
Share on other sites
tempman

Ooops now I see the error :)

Please change $ip to $ip_output in GUICtrlSetData :D

:(

But can be done without F2?

something like Send({F2}) for GUI?

Share this post


Link to post
Share on other sites
monoceres

:)

But can be done without F2?

something like Send({F2}) for GUI?

The simpliest way is to just call the function in the loop.

The problem is that when you use GUIGetMsg() the loop sometimes sleep to much and sometimes too little, therefore I always use OnEventMode this gives IMO more control over your program.

#NoTrayIcon
#include <GuiConstants.au3>
Opt("GUIOnEventMode",1)
GuiCreate("IPset", 400, 400)
GUISetOnEvent(-3,"close")
GuiCtrlCreateTab(5, 5, 390, 350)
GuiCtrlCreateTabItem("IP address")
#Region
$ip = Run(@ComSpec & " /c ipconfig","",@SW_HIDE, 2)
$ip_output=StdoutRead($ip)
$label=GUICtrlCreateLabel ($ip_output, 80, 50, 0, 0) ; Added control id
HotKeySet("{F2}","_refresh") ; add hotkey
#EndRegion

GuiSetState()

While 1
sleep(1000)
_refresh()
WEnd



Func _refresh() ; Function that will be executed when pressing F2
    $ip = Run(@ComSpec & " /c ipconfig","",@SW_HIDE, 2)
    $ip_output=StdoutRead($ip)
    GUICtrlSetData($label,$ip_output)
EndFunc

Func close ()
    Exit
EndFunc

This will update once every second :(


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
tempman

Cheers mate!

Thank you for your time :)

Share this post


Link to post
Share on other sites
weaponx

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "ArpAlwaysSourceRoute: " & $objItem.ArpAlwaysSourceRoute & @CRLF
      $Output = $Output & "ArpUseEtherSNAP: " & $objItem.ArpUseEtherSNAP & @CRLF
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "DatabasePath: " & $objItem.DatabasePath & @CRLF
      $Output = $Output & "DeadGWDetectEnabled: " & $objItem.DeadGWDetectEnabled & @CRLF
      $strDefaultIPGateway = $objItem.DefaultIPGateway(0)
      $Output = $Output & "DefaultIPGateway: " & $strDefaultIPGateway & @CRLF
      $Output = $Output & "DefaultTOS: " & $objItem.DefaultTOS & @CRLF
      $Output = $Output & "DefaultTTL: " & $objItem.DefaultTTL & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "DHCPEnabled: " & $objItem.DHCPEnabled & @CRLF
      $Output = $Output & "DHCPLeaseExpires: " & WMIDateStringToDate($objItem.DHCPLeaseExpires) & @CRLF
      $Output = $Output & "DHCPLeaseObtained: " & WMIDateStringToDate($objItem.DHCPLeaseObtained) & @CRLF
      $Output = $Output & "DHCPServer: " & $objItem.DHCPServer & @CRLF
      $Output = $Output & "DNSDomain: " & $objItem.DNSDomain & @CRLF
      $strDNSDomainSuffixSearchOrder = $objItem.DNSDomainSuffixSearchOrder(0)
      Consolewrite($strDNSDomainSuffixSearchOrder & @CRLF)
      $Output = $Output & "DNSDomainSuffixSearchOrder: " & $strDNSDomainSuffixSearchOrder & @CRLF
      $Output = $Output & "DNSEnabledForWINSResolution: " & $objItem.DNSEnabledForWINSResolution & @CRLF
      $Output = $Output & "DNSHostName: " & $objItem.DNSHostName & @CRLF
      $strDNSServerSearchOrder = $objItem.DNSServerSearchOrder(0)
      $Output = $Output & "DNSServerSearchOrder: " & $strDNSServerSearchOrder & @CRLF
      $Output = $Output & "DomainDNSRegistrationEnabled: " & $objItem.DomainDNSRegistrationEnabled & @CRLF
      $Output = $Output & "ForwardBufferMemory: " & $objItem.ForwardBufferMemory & @CRLF
      $Output = $Output & "FullDNSRegistrationEnabled: " & $objItem.FullDNSRegistrationEnabled & @CRLF
      $strGatewayCostMetric = $objItem.GatewayCostMetric(0)
      $Output = $Output & "GatewayCostMetric: " & $strGatewayCostMetric & @CRLF
      $Output = $Output & "IGMPLevel: " & $objItem.IGMPLevel & @CRLF
      $Output = $Output & "Index: " & $objItem.Index & @CRLF
      $strIPAddress = $objItem.IPAddress(0)
      $Output = $Output & "IPAddress: " & $strIPAddress & @CRLF
      $Output = $Output & "IPConnectionMetric: " & $objItem.IPConnectionMetric & @CRLF
      $Output = $Output & "IPEnabled: " & $objItem.IPEnabled & @CRLF
      $Output = $Output & "IPFilterSecurityEnabled: " & $objItem.IPFilterSecurityEnabled & @CRLF
      $Output = $Output & "IPPortSecurityEnabled: " & $objItem.IPPortSecurityEnabled & @CRLF
      $strIPSecPermitIPProtocols = $objItem.IPSecPermitIPProtocols(0)
      $Output = $Output & "IPSecPermitIPProtocols: " & $strIPSecPermitIPProtocols & @CRLF
      $strIPSecPermitTCPPorts = $objItem.IPSecPermitTCPPorts(0)
      $Output = $Output & "IPSecPermitTCPPorts: " & $strIPSecPermitTCPPorts & @CRLF
      $strIPSecPermitUDPPorts = $objItem.IPSecPermitUDPPorts(0)
      $Output = $Output & "IPSecPermitUDPPorts: " & $strIPSecPermitUDPPorts & @CRLF
      $strIPSubnet = $objItem.IPSubnet(0)
      $Output = $Output & "IPSubnet: " & $strIPSubnet & @CRLF
      $Output = $Output & "IPUseZeroBroadcast: " & $objItem.IPUseZeroBroadcast & @CRLF
      $Output = $Output & "IPXAddress: " & $objItem.IPXAddress & @CRLF
      $Output = $Output & "IPXEnabled: " & $objItem.IPXEnabled & @CRLF
      $strIPXFrameType = $objItem.IPXFrameType(0)
      $Output = $Output & "IPXFrameType: " & $strIPXFrameType & @CRLF
      $Output = $Output & "IPXMediaType: " & $objItem.IPXMediaType & @CRLF
      $strIPXNetworkNumber = $objItem.IPXNetworkNumber(0)
      $Output = $Output & "IPXNetworkNumber: " & $strIPXNetworkNumber & @CRLF
      $Output = $Output & "IPXVirtualNetNumber: " & $objItem.IPXVirtualNetNumber & @CRLF
      $Output = $Output & "KeepAliveInterval: " & $objItem.KeepAliveInterval & @CRLF
      $Output = $Output & "KeepAliveTime: " & $objItem.KeepAliveTime & @CRLF
      $Output = $Output & "MACAddress: " & $objItem.MACAddress & @CRLF
      $Output = $Output & "MTU: " & $objItem.MTU & @CRLF
      $Output = $Output & "NumForwardPackets: " & $objItem.NumForwardPackets & @CRLF
      $Output = $Output & "PMTUBHDetectEnabled: " & $objItem.PMTUBHDetectEnabled & @CRLF
      $Output = $Output & "PMTUDiscoveryEnabled: " & $objItem.PMTUDiscoveryEnabled & @CRLF
      $Output = $Output & "ServiceName: " & $objItem.ServiceName & @CRLF
      $Output = $Output & "SettingID: " & $objItem.SettingID & @CRLF
      $Output = $Output & "TcpipNetbiosOptions: " & $objItem.TcpipNetbiosOptions & @CRLF
      $Output = $Output & "TcpMaxConnectRetransmissions: " & $objItem.TcpMaxConnectRetransmissions & @CRLF
      $Output = $Output & "TcpMaxDataRetransmissions: " & $objItem.TcpMaxDataRetransmissions & @CRLF
      $Output = $Output & "TcpNumConnections: " & $objItem.TcpNumConnections & @CRLF
      $Output = $Output & "TcpUseRFC1122UrgentPointer: " & $objItem.TcpUseRFC1122UrgentPointer & @CRLF
      $Output = $Output & "TcpWindowSize: " & $objItem.TcpWindowSize & @CRLF
      $Output = $Output & "WINSEnableLMHostsLookup: " & $objItem.WINSEnableLMHostsLookup & @CRLF
      $Output = $Output & "WINSHostLookupFile: " & $objItem.WINSHostLookupFile & @CRLF
      $Output = $Output & "WINSPrimaryServer: " & $objItem.WINSPrimaryServer & @CRLF
      $Output = $Output & "WINSScopeID: " & $objItem.WINSScopeID & @CRLF
      $Output = $Output & "WINSSecondaryServer: " & $objItem.WINSSecondaryServer & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapterConfiguration" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

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  

×