Jump to content

Display IP Address, Default Gateway & DNS Servers


Recommended Posts

Thank you guinness!

OK, I finally got what you mean- put the code between the tags, like this:

(code goes here)
.

Now, the window pops open displaying everything exactly as I wanted but it did nothing else. I want it to wait until I press the "Check Addresses" button before it displays, like it did previously. (Sorry for being so picky :unsure:

OK, I moved these two lines that were located at lines 10 & 11, to: lines 168 & 169:

MsgBox(64, "IP Addresses",_IPDetails())
Exit

Now, this version is perfect!..almost.

My goal is to run it on: WinXP, Vista & Win7. I just tried to run it in Win 7- nothing. I am logged in as admin. My older version (script listed below where it does not list all adapters) does work in Win7. Not sure why. Any ideas?

#include <GUIConstants.au3>
; This script requires full Administrative rights
#requireadmin
#AutoIt3Wrapper_UseAnsi=y

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)

Global $aArray = _IPDetails()
Global $sData = "Your IP Address: " & $aArray[1] & @LF & _
        "Your Gateway Address: " & $aArray[3] & @LF & _
        "You DNS Servers: " & $aArray[4]


Select
Case @OSVersion = "WIN_7"
$Parent1 = GUICreate("GBON Tool", 180, 530, 600)
GUICtrlCreateLabel("You have Windows 7" & @CRLF & @CRLF & "Wait 10 sec. after clicking", 25, 20)
GUISetBkColor(0x00CCFF) ; set color (0x33CCCC old color)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ip1 = GUICtrlCreateButton ("Check Addresses", -120, 18, 100, 30)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -100, 20, 100)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -100, 20, 100)
GUICtrlSetOnEvent(-1, "RenewPressed")

$flush = GUICtrlCreateButton ("Flush DNS", -100, 20, 100)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 20, 100)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -100, 20, 100)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Properties", -100, 20, 100)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -100, 20, 100)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("Version 2" & @CRLF & "© Mark Burch, 2011", -100, 20)

GUISetState(@SW_SHOW)   
Case @OSVersion = "WIN_VISTA"
$Parent1 = GUICreate("GBON Tool", 180, 530, 600)
GUICtrlCreateLabel("You have Windows Vista" & @CRLF & @CRLF & "Click button and wait 10" & @CRLF & "sec. for window to open", 32, 20)
GUISetBkColor(0x00CCFF) ; set color

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ip1 = GUICtrlCreateButton ("Check Addresses", -118, 18, 100, 30)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -100, 20, 100)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -100, 20, 100)
GUICtrlSetOnEvent(-1, "RenewPressed")

$flush = GUICtrlCreateButton ("Flush DNS", -100, 20, 100)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 20, 100)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -100, 20, 100)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Properties", -100, 20, 100)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -100, 20, 100)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("Version 2" & @CRLF & "© Mark Burch, 2011", -100, 20)

GUISetState(@SW_SHOW)
Case @OSVersion = "WIN_XP"
$Parent1 = GUICreate("GBON! Tool", 180, 500, 600)
GUICtrlCreateLabel("You have Windows XP" & @CRLF & "" & @CRLF & "Wait 10 sec. after clicking", 25, 20)

GUISetBkColor(0x00CCFF) ; set color

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ip1 = GUICtrlCreateButton ("Check Addresses", -120, 20, 100, 30)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -100, 20, 100)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -100, 20, 100)
GUICtrlSetOnEvent(-1, "RenewPressed")

$flush = GUICtrlCreateButton ("Flush DNS", -100, 20, 100)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 20, 100)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -100, 20, 100)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Options", -100, 20, 100)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -100, 20, 100)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("Version 2" & @CRLF & "© Mark Burch, 2011", -100, 20)

GUISetState(@SW_SHOW)

Case Else
MsgBox(48, "Unsupported OS", "This application is not designed to run on this operating system.")
Exit
EndSelect

; Just idle around
While 1
Sleep(1000)
Wend

Func VerPressed()
Run("winver")
EndFunc

Func IP1Pressed()
MsgBox(0, "Your PC Addresses", $sData)
;$IP_Address = _RunStdOutRead('ipconfig /all')
;$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
;MsgBox(64, "Check IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func ReleasePressed()
$IP_Address = _RunStdOutRead('ipconfig /release')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
MsgBox(64, "Release IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func RenewPressed()
$IP_Address = _RunStdOutRead('ipconfig /renew')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
MsgBox(64, "Renew IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func FlushPressed()
$IP_Address = _RunStdOutRead('netsh int ip delete arpcache & ipconfig/flushdns')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
MsgBox(64, "Flush DNS", StringFormat("%s", $IP_Address))
EndFunc

Func TCPIPPressed()
$IP_Address = _RunStdOutRead('netsh int ip reset resetlog.txt & netsh winsock reset')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
MsgBox(64, "Reset TCP/IP & Winsock", StringFormat("%s", $IP_Address))
EndFunc

;Function to read from Command Line process.
Func _RunStdOutRead($sRunCmd)
Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2)
Local $sStdOutRead = ""

While ProcessExists($iPID)
$sStdOutRead &= StdoutRead($iPID)
WEnd

Return $sStdOutRead
EndFunc

Func Ping4Pressed()
$IP_Address = _RunStdOutRead('ping www.google.com')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1")
MsgBox(64, "Ping Out By URL", StringFormat("%s", $IP_Address))
EndFunc

Func InetPressed()
Run("control inetcpl.cpl")
WinWait("Internet Options", "", 5)
EndFunc

Func ServPressed()
$File = @SystemDir & "\services.msc"
Run(@SystemDir & "\mmc.exe " & $File)
EndFunc

Func SpecialEvents()

Select
Case @GUI_CTRLID = $GUI_EVENT_CLOSE
Exit

Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

EndSelect

EndFunc

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True", "WQL", 0x30), $aReturn[5] = [4]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If $oObjectItem.IPAddress(0) == @IPAddress1 Then
                $aReturn[1] = $oObjectItem.IPAddress(0)
                $aReturn[2] = $oObjectItem.MACAddress
                $aReturn[3] = $oObjectItem.DefaultIPGateway(0)
                $aReturn[4] = _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " and ") ; You could use _ArrayToString() but I like creating my own Functions especially when I don't need alot of error checking.
            EndIf
        Next
        Return $aReturn
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString
Link to comment
Share on other sites

I use Windows 7 x64 and have had no problems.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks guinness.

Don't know why but, my Dell laptop (Win7 Home Premium edition) seem to lock up. Maybe if I'd waited long enough, it would have worked OK.

I decided to just have it open a message window using "winver" like I used to do it on previous version of script- which is really fast on the laptop.

Now, I have tweaked the color, dimensions, etc. Try it now.

#include <GUIConstants.au3>
; This script requires full Administrative rights
#requireadmin
#AutoIt3Wrapper_UseAnsi=y

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)


$Parent1 = GUICreate("GBON Tool", 160, 490, 500) ; width, height, position on screen from left 
GUICtrlCreateLabel("Wait 10 sec. after clicking", 20, 20) ; position on screen from left, down from top
GUISetBkColor(0x00CCFF) ; set color (0x33CCCC old color)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ver = GUICtrlCreateButton ("Windows Version", -120, 15, 100, 25) ; position on screen from left, spaces down, button width, button height
GUICtrlSetOnEvent(-1, "verPressed")

$ip1 = GUICtrlCreateButton ("Check Addresses", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "RenewPressed")

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Wait! Renew may" & @CRLF & "take up to 3 min.", -95, 10) ; position on screen from left, down from top
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$flush = GUICtrlCreateButton ("Flush DNS", -105, 15, 100, 25)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Properties", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -100, 15, 100, 25)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("GBON Tool, Ver 3" & @CRLF & "© Mark Burch, 2011", -95, 15) 
; diff background color, winver works different, shows all enabled network adapter addresses 
; added note about renew ip, changed dimensions, added comments in script
; thanks to users in the AutoIt Forum: sahsanu, guinness, Monamo, MrCreatoR, FreeFry, Kademlia, LIMITER, Squirrely1, DickG, ChrisBair

GUISetState(@SW_SHOW)

; Just idle around
While 1
Sleep(10)
Wend

Func verPressed()
Run("winver")
EndFunc

; Just idle around
While 1
Sleep(10)
Wend

; END

Func IP1Pressed()
MsgBox(64, "Check Addresses",_IPDetails()) ; open widow shows all enabled network adapters
EndFunc

Func ReleasePressed()
$IP_Address = _RunStdOutRead('ipconfig /release')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Release IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func RenewPressed()
$IP_Address = _RunStdOutRead('ipconfig /renew')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Renew IP Address",_IPDetails()) ; open widow shows all enabled network adapters
EndFunc

Func FlushPressed()
$IP_Address = _RunStdOutRead('netsh int ip delete arpcache & ipconfig/flushdns')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Flush DNS", StringFormat("%s", $IP_Address))
EndFunc

Func TCPIPPressed()
$IP_Address = _RunStdOutRead('netsh int ip reset resetlog.txt & netsh winsock reset')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Reset TCP/IP & Winsock", StringFormat("%s", $IP_Address))
EndFunc

;Function to read from Command Line process.
Func _RunStdOutRead($sRunCmd)
Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2)
Local $sStdOutRead = ""

While ProcessExists($iPID)
$sStdOutRead &= StdoutRead($iPID)
WEnd

Return $sStdOutRead
EndFunc

Func Ping4Pressed()
$IP_Address = _RunStdOutRead('ping www.google.com')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Ping Out By URL", StringFormat("%s", $IP_Address))
EndFunc

Func InetPressed()
Run("control inetcpl.cpl")
WinWait("Internet Options", "", 5)
EndFunc

Func ServPressed()
$File = @SystemDir & "\services.msc"
Run(@SystemDir & "\mmc.exe " & $File)
EndFunc

Func SpecialEvents()

Select
Case @GUI_CTRLID = $GUI_EVENT_CLOSE
Exit

Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

EndSelect

EndFunc

MsgBox(64, "IP Addresses",_IPDetails())
Exit

Func _IPDetails()
    Local $totalReturn=""
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[6] = [5]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
        If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[2] = "IP Address:" & @TAB & "Not Available"
                EndIf
                If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[3] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                     $aReturn[4] = "DNS Servers:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.MACAddress) Then
                    $aReturn[5] = "MAC: " & @TAB & @TAB & $oObjectItem.MACAddress
                Else
                    $aReturn[5] = "MAC: " & @TAB & @TAB & "Not Available"
                EndIf

            $totalReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] &  @CRLF & $aReturn[4] &  @CRLF & $aReturn[5] & @CRLF & @CRLF
            EndIf
        Next
        Return StringTrimRight($totalReturn,4)
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString
Link to comment
Share on other sites

guinness I have one request.

A new change I added was to Reset both the IP Address & DNS Servers to "Obtain Automatically" when TCP/IP & Winsock button was pressed.

How can I make it show if "Obtain IP Address Automatically" or "Obtain DNS Server Address Automatically" have been changed?

For the "Check Addresses" button, I took out the MAC Address (which was great but I'd rather have it show if DHCP is enabled or, not - about line 188.)

I tried different variations to show if DHCP was enabled but I just could not figure it out. Google search did not give me and easy answer.

If I could find a way to show the status of the "Obtain IP Address Automatically" radio button, that would work.

#include <GUIConstants.au3>
; This script requires full Administrative rights
#requireadmin
#AutoIt3Wrapper_UseAnsi=y

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)


$Parent1 = GUICreate("GBON Tool", 170, 520, 500) ; width, height, position on screen from left 
GUICtrlCreateLabel("Wait 10 sec. after clicking", 20, 20) ; position on screen from left, down from top
GUISetBkColor(0x00CCFF) ; set color (0x33CCCC old color)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ver = GUICtrlCreateButton ("Windows Version", -125, 15, 120, 25) ; position on screen from left, spaces down, button width, button height
GUICtrlSetOnEvent(-1, "verPressed")

$nc1 = GUICtrlCreateButton ("Network Connections", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "NC1Pressed")

$ip1 = GUICtrlCreateButton ("Check Addresses", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "RenewPressed")

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Wait! Renew may" & @CRLF & "take up to 3 min.", -105, 10) ; position on screen from left, down from top
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$flush = GUICtrlCreateButton ("Flush DNS", -135, 15, 120, 25)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Properties", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("GBON Tool, Ver 3" & @CRLF & "© Mark Burch, 2011", -105, 15) 
; diff background color, winver works different, shows all enabled network adapter addresses 
; added note about renew ip, changed dimensions, added comments in script
; thanks to users in the AutoIt Forum: sahsanu, guinness, Monamo, MrCreatoR, FreeFry, Kademlia, LIMITER, Squirrely1, DickG, ChrisBair

GUISetState(@SW_SHOW)

; Just idle around
While 1
Sleep(10)
Wend

Func verPressed()
Run("winver")
EndFunc

; Just idle around
While 1
Sleep(10)
Wend

; END

Func NC1Pressed()
Run("control ncpa.cpl")
WinWait("Network Connections", "", 5)
EndFunc

Func IP1Pressed()
MsgBox(64, "Check Addresses",_IPDetails()) ; open widow shows all enabled network adapters
EndFunc

Func ReleasePressed()
$IP_Address = _RunStdOutRead('ipconfig /release')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Release IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func RenewPressed()
$IP_Address = _RunStdOutRead('ipconfig /renew')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Renew IP Address",_IPDetails()) ; open widow shows all enabled network adapters
EndFunc

Func FlushPressed()
$IP_Address = _RunStdOutRead('netsh int ip delete arpcache & ipconfig/flushdns')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Flush DNS", StringFormat("%s", $IP_Address))
EndFunc

;Function to Reset IP Address & DNS to "Obtain Automatically", Reset TCP/IP & Reset Winsock.
Func TCPIPPressed()
$Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" source=dhcp", "", @SW_hide)
$Run = Run(@ComSpec & " /c " & "netsh interface ip set dns name=""Local Area Connection"" source=dhcp", "", @SW_hide)
$IP_Address = _RunStdOutRead('netsh int ip reset resetlog.txt & netsh winsock reset')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Reset TCP/IP & Winsock", StringFormat("%s", $IP_Address))
EndFunc

;Function to read from Command Line process.
Func _RunStdOutRead($sRunCmd)
Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2)
Local $sStdOutRead = ""

While ProcessExists($iPID)
$sStdOutRead &= StdoutRead($iPID)
WEnd

Return $sStdOutRead
EndFunc

Func Ping4Pressed()
$IP_Address = _RunStdOutRead('ping www.google.com')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Ping Out By URL", StringFormat("%s", $IP_Address))
EndFunc

Func InetPressed()
Run("control inetcpl.cpl,@0,6")
WinWait("Internet Options", "", 5)
EndFunc

Func ServPressed()
$File = @SystemDir & "\services.msc"
Run(@SystemDir & "\mmc.exe " & $File)
EndFunc

Func SpecialEvents()

Select
Case @GUI_CTRLID = $GUI_EVENT_CLOSE
Exit

Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

EndSelect

EndFunc

MsgBox(64, "IP Addresses",_IPDetails())
Exit

Func _IPDetails()
    Local $totalReturn=""
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[6] = [5]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
        If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[2] = "IP Address:" & @TAB & "Not Available"
                EndIf
                If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[3] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                     $aReturn[4] = "DNS Servers:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.DHCPEnabled) Then
                    $aReturn[5] = "DHCP: " & @TAB & @TAB & $oObjectItem.DHCPEnabled
                Else
                    $aReturn[5] = "DHCP: " & @TAB & @TAB & "Not Available"
                EndIf


            $totalReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] &  @CRLF & $aReturn[4] &  @CRLF & $aReturn[5] & @CRLF & @CRLF
            EndIf
        Next
        Return StringTrimRight($totalReturn,4)
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString

Thanks.

Link to comment
Share on other sites

Like this?

MsgBox(64, "IP Addresses", _IPDetails())
Exit

Func _IPDetails()
    Local $sReturn = ""
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[6] = [5]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[2] = "IP Address:" & @TAB & "Not Available"
                EndIf
                If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[3] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                    $aReturn[4] = "DNS Servers:" & @TAB & "Not Available"
                EndIf

                If IsBool($oObjectItem.DHCPEnabled) Then
                    $aReturn[5] = "DHCP: " & @TAB & @TAB & $oObjectItem.DHCPEnabled
                Else
                    $aReturn[5] = "DHCP: " & @TAB & @TAB & "Not Available"
                EndIf
                $sReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] & @CRLF & $aReturn[4] & @CRLF & $aReturn[5] & @CRLF & @CRLF
            EndIf
        Next
        Return StringTrimRight($sReturn, 4)
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks guinness!

Yes!

OK, now a new situation came up. I disabled both Ethernet cards and the Wireless Adapter (to simulate a customer's adapter disabled- but they do not know it. When I click "Check Addresses", a message box opens but, it is blank.

Is there a way to make it say "No adapters found"- or something like that?

I'm not sure what value to check for. With all adapters disabled, I know that in the command window, it will not show any info, either.

Maybe a string that looks for a MAC Address but, if none are found, it could print in the message box, "No adapters found".

I tried adding this:

If IsString($oObjectItem.MACAddress) = "" Then

$aReturn[6] = "No adapters found"

EndIf

..but, it did nothing- still just an open message window that is blank.

Tried:

If "MACAddress" = "" Then

$aReturn[6] = "No adapters found"

EndIf

..but, it did nothing- still just an open message window that is blank.

I tried looking for something on the Internet but, nothing close to this task was found. I'm sorry, I know what I want it to do, but just don't know programing enough to know the synatx.

Link to comment
Share on other sites

OK, I personally wouldn't do it this way but I believe you weren't happy with my 3 Examples I gave you so I'm still using the Version modified by sahsanu (sorry!) :unsure:

I used @extended to show how many Adapters with a correct IP Address were found using SetError() (look in the Help File!) I also made sure the grammar of whether 1 or more adapters was correct i.e. Was & Were!

Global $sIPDetails = _IPDetails()
Global $iExtended = @extended
Switch $iExtended
    Case 0
        $iExtended = ""
    Case 1
        $iExtended = @CRLF & @CRLF & "The total number of adapters found was " & $iExtended & "."
    Case Else
        $iExtended = @CRLF & @CRLF & "The total number of adapters found were " & $iExtended & "."
EndSwitch
MsgBox(64, "IP Addresses", $sIPDetails & $iExtended)
Exit

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[6] = [5], $sReturn = "", $iCount = 0
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[2] = "IP Address:" & @TAB & "Not Available"
                EndIf
                If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[3] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                    $aReturn[4] = "DNS Servers:" & @TAB & "Not Available"
                EndIf

                If IsBool($oObjectItem.DHCPEnabled) Then
                    $aReturn[5] = "DHCP: " & @TAB & @TAB & $oObjectItem.DHCPEnabled
                Else
                    $aReturn[5] = "DHCP: " & @TAB & @TAB & "Not Available"
                EndIf
                $sReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] & @CRLF & $aReturn[4] & @CRLF & $aReturn[5] & @CRLF & @CRLF
                $iCount += 1
            EndIf
        Next
        If $iCount > 0 Then
            Return SetError(0, $iCount, StringTrimRight($sReturn, 4))
        EndIf
        Return SetError(1, $iCount, "No Adapters Available.")
    EndIf
    Return SetError(1, 0, "No Adapters Available.")
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString

But I would highly recommend looking through the forums on WMI & checking the Return values of IsString() (this is perhaps why your example didn't work!)

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks again, guinness!

I actually did look for WMI stuff and "isstring". The problem is, since I do not understand what each string is doing, it's like me trying to read and understand the greek language- bunch of characters that do not make sense.

I tried a coule of things that I found but because I was just taking a couple of lines, I got errors about "not defined"- so I wasn't getting enough of the script to make it work.

What was it you said about 3 examples?- I loved all the scripts you provided. After I started using them, I just wanted to tweak them a bit, that's all.

Before your current submission (which I will try wheh I get home from work), I could've left it alone. When all network adapters were disabled (which happens to my customers!), it had a blank window. I just wanted a message so they will see some words.

Thanks again for all your work- you and all the others who sent in suggestions are awesome!

Link to comment
Share on other sites

OK, you're welcome.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Sorry, Guinness, one more task.

I am trying to show if "Obtain DNS Automatically" is selected or, a static IP has been entered.

Lines 208 - 222 were added. The problem is, it always shows "True"- even when a static IP has been entered (which I want to show "False".

#include <GUIConstants.au3>
; This script requires full Administrative rights
#requireadmin
#AutoIt3Wrapper_UseAnsi=y

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)


$Parent1 = GUICreate("GBON", 170, 520, 500) ; width, height, position on screen from left 
GUICtrlCreateLabel("Wait 10 sec. after clicking", 20, 20) ; position on screen from left, down from top
GUISetBkColor(0x00CCFF) ; set color (0x33CCCC old color)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ver = GUICtrlCreateButton ("Windows Version", -125, 15, 120, 25) ; position on screen from left, spaces down, button width, button height
GUICtrlSetOnEvent(-1, "verPressed")

$nc1 = GUICtrlCreateButton ("Network Connections", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "NC1Pressed")

$ip1 = GUICtrlCreateButton ("Check Addresses", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "RenewPressed")

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Wait! Renew may" & @CRLF & "take up to 3 min.", -105, 10) ; position on screen from left, down from top
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$flush = GUICtrlCreateButton ("Flush DNS", -135, 15, 120, 25)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Properties", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("GBON Tool, Ver 3" & @CRLF & "© Mark Burch, 2011", -105, 15) 
; diff background color, winver works different, shows all enabled network adapter addresses 
; added note about renew ip, changed dimensions, added comments in script
; thanks to users in the AutoIt Forum: sahsanu, guinness, Monamo, MrCreatoR, FreeFry, Kademlia, LIMITER, Squirrely1, DickG, ChrisBair

GUISetState(@SW_SHOW)

; Just idle around
While 1
Sleep(10)
Wend

Func verPressed()
Run("winver")
EndFunc

; Just idle around
While 1
Sleep(10)
Wend

; END

Func NC1Pressed()
Run("control ncpa.cpl")
WinWait("Network Connections", "", 5)
EndFunc

Func IP1Pressed()
MsgBox(64, "Check Addresses",_IPDetails()) ; open widow shows all enabled network adapters
EndFunc

Func ReleasePressed()
$IP_Address = _RunStdOutRead('ipconfig /release')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Release IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func RenewPressed()
$IP_Address = _RunStdOutRead('ipconfig /renew')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Renew IP Address",_IPDetails()) ; open widow shows all enabled network adapters
EndFunc

Func FlushPressed()
$IP_Address = _RunStdOutRead('netsh int ip delete arpcache & ipconfig/flushdns')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Flush DNS", StringFormat("%s", $IP_Address))
EndFunc

;Function to Reset IP Address & DNS to "Obtain Automatically", Reset TCP/IP & Reset Winsock.
Func TCPIPPressed()
$Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" source=dhcp", "", @SW_hide)
$Run = Run(@ComSpec & " /c " & "netsh interface ip set dns name=""Local Area Connection"" source=dhcp", "", @SW_hide)
$IP_Address = _RunStdOutRead('netsh int ip reset resetlog.txt & netsh winsock reset')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Reset TCP/IP & Winsock", StringFormat("%s", $IP_Address))
EndFunc

;Function to read from Command Line process.
Func _RunStdOutRead($sRunCmd)
Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2)
Local $sStdOutRead = ""

While ProcessExists($iPID)
$sStdOutRead &= StdoutRead($iPID)
WEnd

Return $sStdOutRead
EndFunc

Func Ping4Pressed()
$IP_Address = _RunStdOutRead('ping www.google.com')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Ping Out By URL", StringFormat("%s", $IP_Address))
EndFunc

Func InetPressed()
Run("control inetcpl.cpl,@0,6")
WinWait("Internet Options", "", 5)
EndFunc

Func ServPressed()
$File = @SystemDir & "\services.msc"
Run(@SystemDir & "\mmc.exe " & $File)
EndFunc

Func SpecialEvents()

Select
Case @GUI_CTRLID = $GUI_EVENT_CLOSE
Exit

Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

EndSelect

EndFunc

MsgBox(64, "IP Addresses", _IPDetails())
Exit

Global $sIPDetails = _IPDetails()
Global $iExtended = @extended
Switch $iExtended
    Case 0
        $iExtended = ""
    Case 1
        $iExtended = @CRLF & @CRLF & "The total number of adapters found was " & $iExtended & "."
    Case Else
        $iExtended = @CRLF & @CRLF & "The total number of adapters found were " & $iExtended & "."
EndSwitch
MsgBox(64, "IP Addresses", $sIPDetails & $iExtended)
Exit

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[8] = [6], $sReturn = "", $iCount = 0
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[2] = "IP Address:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[3] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                    $aReturn[4] = "DNS Servers:" & @TAB & "Not Available"
                EndIf


                If IsBool($oObjectItem.DHCPEnabled) Then
                    $aReturn[5] = "Auto IP: " & @TAB & @TAB & $oObjectItem.DHCPEnabled
                Else
                    $aReturn[5] = "Auto IP: " & @TAB & @TAB & "Not Available"
                EndIf

                Dim $aInterface [5]
                For $i= 1 to 5 ; Max 5 Interfaces
                    $var = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $i)
                    If @error <> 0 then ExitLoop
                    $aInterface [$i] = $var
                Next
                For $i = 1 To UBound ($aInterface) - 1
                If RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface [$i], "NameServer") = "" Then           
                    $aReturn[6] = "Auto DNS: " & @TAB & "True" ; If "NameServer" is empty, "True" means "Obtain DNS Automatically" is selected 
                If RegRead ("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface [$i], "NameServer") <> "" Then          
                    $aReturn[6] = "Auto DNS: " & @TAB & "False" ; If "NameServer" has an address, "False" means "Use the following DNS Addess" is selected
                EndIf
                Else
                    $aReturn[6] = "Auto DNS: " & @TAB & "Not Available"
                EndIf

        Next
        $sReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] & @CRLF & $aReturn[4] & @CRLF & $aReturn[5] & @CRLF & $aReturn[6] & @CRLF & @CRLF
                $iCount += 1
        EndIf
        Next
        If $iCount > 0 Then
            Return SetError(0, $iCount, StringTrimRight($sReturn, 4))
        EndIf
        Return SetError(1, $iCount, "No Adapters Available.")
    EndIf
    Return SetError(1, 0, "No Adapters Available.")
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString
Link to comment
Share on other sites

OK,

1. Don't use Dim, I would recommend using Local/Global depending on where you declare the Variables. If in a Function use Local or if the Variable is declared multiple times in the Script then use Global.

2. If you hit Ctrl+F5 it will show the errors in the Script which is why it doesn't work. I would recommend using SciTE4AutoIt3 and also use Ctrl+T to "Tidy" the code.

3. If you read about If...Statements in the Help File this should help you with your problem.

4. I have updated the code but haven't tested.

If RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface[$i], "NameServer") = "" And @error = 0 Then
    $aReturn[6] = "Auto DNS: " & @TAB & "True" ; If "NameServer" is empty, "True" means "Obtain DNS Automatically" is selected
ElseIf RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface[$i], "NameServer") <> "" And @error = 0 Then
    $aReturn[6] = "Auto DNS: " & @TAB & "False" ; If "NameServer" has an address, "False" means "Use the following DNS Addess" is selected
Else
    $aReturn[6] = "Auto DNS: " & @TAB & "Not Available"
EndIf
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thanks guinness.

Unfortunately, your last suggestion only gives "Not Available" for all three adapters.

All I want it to do is read a value in the registry and print "True" if the value has no entry. If there is any data found, print "False".

Basically, I want to tell the user if "Obtain DNS Automatically" is selected or if a DNS address has been entered.

Everything else works great but, right now you cannot tell if the DNS Address was obtained "Automatically" or entered manually.

I tried tweaking your last suggestion but this version always says "True"- even though my Internet Protocol Version 4 (TCP/IPv4) has a DNS entered manually for one Ethernet card.

FYI- I have 2 Ethernet cards and a Wireless Adapter installed so that if users have a similar configuration, it will have all the adapters

listed in the message window with the details. (I could just do ipconfig/all but, I think it has too much info for the average user and the message window looks more professional:)

My OS is Vista but, I want it to work on WinXP, Vista & Win7. (Testing on Vista right now.)

Your original section:

Dim $aInterface [5]
For $i= 1 to 5 ; Max 5 Interfaces
    $var = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $i)
    If @error <> 0 then ExitLoop
    $aInterface [$i] = $var
Next
For $i = 1 To UBound ($aInterface) - 1
If RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface[$i], "NameServer") = "" And @error = 0 Then
    $aReturn[6] = "Auto DNS: " & @TAB & "True" ; If "NameServer" is empty, "True" means "Obtain DNS Automatically" is selected
ElseIf RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface[$i], "NameServer") <> "" And @error = 0 Then
    $aReturn[6] = "Auto DNS: " & @TAB & "False" ; If "NameServer" has an address, "False" means "Use the following DNS Addess" is selected
Else
    $aReturn[6] = "Auto DNS: " & @TAB & "Not Available"
EndIf

Whole script with "Tweaked" section ("Tweaked" section starts about line 215):

#include <GUIConstants.au3>
; This script requires full Administrative rights
#requireadmin
#AutoIt3Wrapper_UseAnsi=y

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)


$Parent1 = GUICreate("GBON", 170, 520, 500) ; width, height, position on screen from left 
GUICtrlCreateLabel("Wait 10 sec. after clicking", 20, 20) ; position on screen from left, down from top
GUISetBkColor(0x00CCFF) ; set color (0x33CCCC old color)

GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$ver = GUICtrlCreateButton ("Windows Version", -125, 15, 120, 25) ; position on screen from left, spaces down, button width, button height
GUICtrlSetOnEvent(-1, "verPressed")

$nc1 = GUICtrlCreateButton ("Network Connections", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "NC1Pressed")

$ip1 = GUICtrlCreateButton ("Check Addresses", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "IP1Pressed")

$release = GUICtrlCreateButton ("Release IP", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "ReleasePressed")

$renew = GUICtrlCreateButton ("Renew IP", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "RenewPressed")

GUISetState(@SW_SHOW)

GUICtrlCreateLabel("Wait! Renew may" & @CRLF & "take up to 3 min.", -105, 10) ; position on screen from left, down from top
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

$flush = GUICtrlCreateButton ("Flush DNS", -135, 15, 120, 25)
GUICtrlSetOnEvent(-1, "FlushPressed")

$tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "TCPIPPressed")

$ping4 = GUICtrlCreateButton ("Ping Google", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "Ping4Pressed")

$inet = GUICtrlCreateButton ("Internet Properties", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "InetPressed")

$serv = GUICtrlCreateButton ("Check Services", -120, 15, 120, 25)
GUICtrlSetOnEvent(-1, "ServPressed")

GUICtrlCreateLabel("GBON Tool, Ver 3" & @CRLF & "© Mark Burch, 2011", -105, 15) 
; diff background color, winver works different, shows all enabled network adapter addresses 
; added note about renew ip, changed dimensions, added comments in script
; thanks to users in the AutoIt Forum: sahsanu, guinness, Monamo, MrCreatoR, FreeFry, Kademlia, LIMITER, Squirrely1, DickG, ChrisBair

GUISetState(@SW_SHOW)

; Just idle around
While 1
Sleep(10)
Wend

Func verPressed()
Run("winver")
EndFunc

; Just idle around
While 1
Sleep(10)
Wend

; END

Func NC1Pressed()
Run("control ncpa.cpl")
WinWait("Network Connections", "", 5)
EndFunc

Func IP1Pressed()
MsgBox(64, "Check Addresses",_IPDetails()) ; open a widow that shows all enabled network adapters
EndFunc

Func ReleasePressed()
$IP_Address = _RunStdOutRead('ipconfig /release')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Release IP Address", StringFormat("Your IP Address is: %s", $IP_Address))
EndFunc

Func RenewPressed()
$IP_Address = _RunStdOutRead('ipconfig /renew')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Renew IP Address",_IPDetails()) ; open a widow that shows all enabled network adapters
EndFunc

Func FlushPressed()
$IP_Address = _RunStdOutRead('netsh int ip delete arpcache & ipconfig/flushdns')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Flush DNS", StringFormat("%s", $IP_Address)) ;flush the DNS
EndFunc

;Function Resets IP & DNS Addresses to "Obtain Automatically" then, Resets TCP/IP & Winsock.
Func TCPIPPressed()
$Run = Run(@ComSpec & " /c " & "netsh interface ip set address name=""Local Area Connection"" source=dhcp", "", @SW_hide)
$Run = Run(@ComSpec & " /c " & "netsh interface ip set dns name=""Local Area Connection"" source=dhcp", "", @SW_hide)
$IP_Address = _RunStdOutRead('netsh int ip reset resetlog.txt & netsh winsock reset')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Reset TCP/IP & Winsock", StringFormat("%s", $IP_Address))
EndFunc

;Function to read from Command Line process.
Func _RunStdOutRead($sRunCmd)
Local $iPID = Run(@ComSpec & ' /c ' & $sRunCmd, @ScriptDir, @SW_HIDE, 4 + 2)
Local $sStdOutRead = ""

While ProcessExists($iPID)
$sStdOutRead &= StdoutRead($iPID)
WEnd

Return $sStdOutRead
EndFunc

;Function to Ping Google from Command Line process.
Func Ping4Pressed()
$IP_Address = _RunStdOutRead('ping www.google.com')
$IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;", "\1")
MsgBox(64, "Ping Out By URL", StringFormat("%s", $IP_Address))
EndFunc

;Function opens Internet Options window and clicks the Advanced tab.
Func InetPressed()
Run("control inetcpl.cpl,@0,6")
WinWait("Internet Options", "", 5)
EndFunc

;Function opens Services window
Func ServPressed()
$File = @SystemDir & "\services.msc"
Run(@SystemDir & "\mmc.exe " & $File)
EndFunc

;Function defines Minimize and Close options for the GBON Tool
Func SpecialEvents()

Select
Case @GUI_CTRLID = $GUI_EVENT_CLOSE
Exit

Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

Case @GUI_CTRLID = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)

EndSelect

EndFunc

; Open a Message window that shows: Description, IP Address, Default Gateway, DNS Server Addresses, 
; If "Obtain IP Adress Automatically" is selected (Auto IP) and If "Obtain DNS Address Automatically" is selected (Auto DNS) 
MsgBox(64, "IP Addresses", _IPDetails())
Exit

Global $sIPDetails = _IPDetails()
Global $iExtended = @extended
Switch $iExtended
    Case 0
        $iExtended = ""
    Case 1
        $iExtended = @CRLF & @CRLF & "The total number of adapters found was " & $iExtended & "."
    Case Else
        $iExtended = @CRLF & @CRLF & "The total number of adapters found were " & $iExtended & "."
EndSwitch
MsgBox(64, "IP Addresses", $sIPDetails & $iExtended)
Exit

Func _IPDetails()
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration", "WQL", 0x30), $aReturn[8] = [6], $sReturn = "", $iCount = 0
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems

            If IsString($oObjectItem.IPAddress(0)) Then
                If IsString($oObjectItem.Description) Then
                    $aReturn[1] = "Description:" & @TAB & $oObjectItem.Description
                Else
                    $aReturn[1] = "Description:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.IPAddress(0)) Then
                    $aReturn[2] = "IP Address:" & @TAB & $oObjectItem.IPAddress(0)
                Else
                    $aReturn[2] = "IP Address:" & @TAB & "Not Available"
                EndIf

                If IsString($oObjectItem.DefaultIPGateway(0)) Then
                    $aReturn[3] = "Default Gateway:" & @TAB & $oObjectItem.DefaultIPGateway(0)
                Else
                    $aReturn[3] = "Default Gateway:" & @TAB & "Not Available"
                EndIf

                If IsArray($oObjectItem.DNSServerSearchOrder()) Then
                    $aReturn[4] = "DNS Servers:" & @TAB & _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")
                Else
                    $aReturn[4] = "DNS Servers:" & @TAB & "Not Available"
                EndIf


                If IsBool($oObjectItem.DHCPEnabled) Then
                    $aReturn[5] = "Auto IP: " & @TAB & @TAB & $oObjectItem.DHCPEnabled
                Else
                    $aReturn[5] = "Auto IP: " & @TAB & @TAB & "Not Available"
                EndIf
        
                Dim $aInterface [5]
                For $i= 1 to 5 ; Max 5 Interfaces
                    $var = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces", $i)
                If @error <> 0 then ExitLoop
                    $aInterface [$i] = $var
                Next
                For $i = 1 To UBound ($aInterface) - 1
                $Key = RegRead("HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $aInterface[$i], "NameServer")
                If $Key = "" Then
                    $aReturn[6] = "Auto DNS: " & @TAB & "True" ; If "NameServer" is empty, "True" means "Obtain DNS Automatically" is selected
                ElseIf $Key <> "" Then
                    $aReturn[6] = "Auto DNS: " & @TAB & "False" ; If "NameServer" has an address, "False" means "Use the following DNS Addess" is selected
                Else
                    $aReturn[6] = "Auto DNS: " & @TAB & "Not Available"
                EndIf
                Next
                    $sReturn &= $aReturn[1] & @CRLF & $aReturn[2] & @CRLF & $aReturn[3] & @CRLF & $aReturn[4] & @CRLF & $aReturn[5] & @CRLF & $aReturn[6] & @CRLF & @CRLF 
                    $iCount += 1
                EndIf
        Next
        If $iCount > 0 Then
            Return SetError(0, $iCount, StringTrimRight($sReturn, 4))
        EndIf
        Return SetError(1, $iCount, "No Adapters Available.")
    EndIf
    Return SetError(1, 0, "No Adapters Available.")
EndFunc   ;==>_IPDetails

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString

I have looked into using Global and Local instead of Dim but, to be honest, it seems like too much of a learning curve for me right now.

"SyntaxCheck Prod" says there are no errors. (Yes, I use this all the time to check for errors.)

I know that the value that must be looked at and processed is for: "NameServer" in the registry located at:

HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\(adapter label). I just cannot figure out how to write the script that says

"If the value for "NameServer" is blank, print "True" but, if it has a value (any value?) in there, print "False".

Any other ideas?

Thanks.

Link to comment
Share on other sites

I will have a look at a solution this week.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

wowmarkb, I'd suggest rather to use WMI to get the values for DHCP and so on, as it keeps it simple, rather than having to read WMI values to a registry function. You can find a good example of what is available for Adapter information using WMI in my previous post with the example.

Hope it helps:)

Edited by katoNkatoNK
Link to comment
Share on other sites

Thanks, guinness.

katoNkatoNK- I'll take a look.

I feel so close to the answer, it may be at one of these sites:

Good info on RegRead:

http://windowssecrets.com/forums/showthread.php/82437-User-Friendly-Access-of-Program-Version

Link to comment
Share on other sites

(I don't expect you to code up anything for a reply but ofc it would be helpful, or even just a mass of references )

This is your answer >> http://www.eggheadcafe.com/software/aspnet/29368848/wmi-for-querying-obtain-dns-server-address-automatically.aspx Let me know if you have problems. You can use my _IPDetails with SettingID & then read the Registry.

wowmarkb, I'd suggest rather to use WMI to get the values for DHCP and so on, as it keeps it simple, rather than having to read WMI values to a registry function. You can find a good example of what is available for Adapter information using WMI in my previous post with the example.

katoNkatoNK - I think I have been quite helpful up until now with many WMI Examples! :unsure: Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Like this for Example >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <Array.au3>

Global $aArray = _IPDetails(), $sData
_ArrayDisplay($aArray)

For $A = 1 To $aArray[0][0]
    $sData &= "Description: " & $aArray[$A][0] & @CRLF & "IP Address: " & $aArray[$A][1] & @CRLF & "MAC: " & _
            $aArray[$A][2] & @CRLF & "Default Gateway: " & $aArray[$A][3] & @CRLF & "DNS Servers: " & $aArray[$A][4] & @CRLF & "Obtain DNS Automatically: " & $aArray[$A][5] & @CRLF & @CRLF
Next
$sData = StringTrimRight($sData, 4)

MsgBox(0, "_IPDetails()", $sData)

Func _IPDetails()
    Local $iCount = 0
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True", "WQL", 0x30), $aReturn[1][6] = [[0, 6]]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            $aReturn[0][0] += 1
            $iCount += 1

            If $aReturn[0][0] <= $iCount + 1 Then
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]
            EndIf

            $aReturn[$iCount][0] = _IsString($oObjectItem.Description)
            $aReturn[$iCount][1] = _IsString($oObjectItem.IPAddress(0))
            $aReturn[$iCount][2] = _IsString($oObjectItem.MACAddress)
            $aReturn[$iCount][3] = _IsString($oObjectItem.DefaultIPGateway(0))
            $aReturn[$iCount][4] = _IsString(_WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")) ; You could use _ArrayToString() but I like creating my own Functions especially when I don't need alot of error checking.
            $aReturn[$iCount][5] = _WMIRegRead($oObjectItem.SettingID)
        Next
        ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]]
        Return $aReturn
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails

Func _WMIRegRead($iGUID)
    If RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $iGUID & "\", "NameServer") = "" Then
        Return True
    EndIf
    Return False
EndFunc   ;==>_WMIRegRead

Func _IsString($sString)
    If IsString($sString) Then
        Return $sString
    EndIf
    Return "Not Available"
EndFunc   ;==>_IsString

Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "Not Available")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

We are almost there!

OK, I had to change some $aArray[$A] numbers, the [x] value, to match the label on the second window that pops up because they were showing the wrong data. For example: Default Gateway had the MAC Address listed next to it, DNS Servers had the Default Gaeway listed and the MAC had the DNS Servers listed.

The numbers should be: Description [0], IP Address [1], Default Gateway [3], DNS Servers [4], Mac [2], Obtain DNS Automatically [5].

The other thing I changed was True and False were backwards. (When "Nameserver" has an address inside, it means not set to "Obtaion DNS Automatically".

Here's my changes:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <Array.au3>

Global $aArray = _IPDetails(), $sData
_ArrayDisplay($aArray) ; First box opens- "List View Display"

For $A = 1 To $aArray[0][0]
    $sData &= "Description: " & $aArray[$A][0] & @CRLF & "IP Address: " & $aArray[$A][1] & @CRLF & "Default Gateway: " & _
            $aArray[$A][3] & @CRLF & "DNS Servers: " & $aArray[$A][4] & @CRLF & "MAC: " & $aArray[$A][2] & @CRLF & "Obtain DNS Automatically: " & $aArray[$A][5] & @CRLF & @CRLF
Next
$sData = StringTrimRight($sData, 4)

MsgBox(0, "Address Information", $sData) ; Second box opens showing the data in a neat format

Func _IPDetails()
    Local $iCount = 0
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2")
    Local $oColItems = $oWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True", "WQL", 0x30), $aReturn[1][6] = [[0, 6]]
    If IsObj($oColItems) Then
        For $oObjectItem In $oColItems
            $aReturn[0][0] += 1
            $iCount += 1

            If $aReturn[0][0] <= $iCount + 1 Then
                ReDim $aReturn[$aReturn[0][0] * 2][$aReturn[0][1]]
            EndIf
            $aReturn[$iCount][0] = _IsString($oObjectItem.Description)
            $aReturn[$iCount][1] = _IsString($oObjectItem.IPAddress(0))
            $aReturn[$iCount][2] = _IsString($oObjectItem.MACAddress)
            $aReturn[$iCount][3] = _IsString($oObjectItem.DefaultIPGateway(0))
            $aReturn[$iCount][4] = _IsString(_WMIArrayToString($oObjectItem.DNSServerSearchOrder(), " - ")) ; You could use _ArrayToString() but I like creating my own Functions especially when I don't need alot of error checking.
    $aReturn[$iCount][5] = _WMIRegRead($oObjectItem.SettingID) ; "Obtain DNS Server Automatically" setting - "True" means no address entered  

    Next

        ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]]
        Return $aReturn
    EndIf
    Return SetError(1, 0, $aReturn)
EndFunc   ;==>_IPDetails
Func _WMIRegRead($iGUID)
    If RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $iGUID & "\", "NameServer") = "" Then
        Return True
    EndIf
    Return False
EndFunc   ;==>_WMIRegRead

Func _IsString($sString)
    If IsString($sString) Then
        Return $sString
    EndIf
    Return "Not Available"
EndFunc   ;==>_IsString
Func _WMIArrayToString($aArray, $sDelimeter = "|")
    If IsArray($aArray) = 0 Then
        Return SetError(1, 0, "Not Available")
    EndIf
    Local $iUbound = UBound($aArray) - 1, $sString
    For $A = 0 To $iUbound
        $sString &= $aArray[$A] & $sDelimeter
    Next
    Return StringTrimRight($sString, StringLen($sDelimeter))
EndFunc   ;==>_WMIArrayToString

Now, in the previous version we had "Obtain IP Address Automatically" listed (the Value was DHCPEnabled) and we called it "Auto IP" in the message box.

When I try to add anything like: $aReturn[$iCount][5] = _IsString($oObjectItem.DHCPEnabled)

and change this line: $aReturn[$iCount][5] = _WMIRegRead($oObjectItem.SettingID) ... to a [6], I get this error:

(33) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aReturn[$iCount][6] = _WMIRegRead($oObjectItem.SettingID)

^ ERROR

..no matter what other values I change.

I even tried to add another WMIRegRead line but, it didn't like 2 lines of WMIRegRead or, it would only read one but, not both.

How can we add "Obtain IP Address Automatically" and show in the message box right above "Obtain DNS Server Automatically"?

Thanks

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...