wowmarkb Posted May 4, 2011 Share Posted May 4, 2011 I have a GUI with buttons. When the IP Address button is pressed, it runs the script (below) and displays the IP Address in a window. Now, I would like the window to display all of the following information: IP Address, Default Gateway & DNS Servers. What do I need to add to show them all? Thanks. /////////// Start Func IP1Pressed() $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 ; Just idle around While 1 Sleep(10) Wend ; END /////////// End Link to comment Share on other sites More sharing options...
JScript Posted May 4, 2011 Share Posted May 4, 2011 Try using WMI, do a search on the forum and you'll see many examples... http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!) Somewhere Out ThereJames Ingram Download Dropbox - Simplify your life!Your virtual HD wherever you go, anywhere! Link to comment Share on other sites More sharing options...
guinness Posted May 4, 2011 Share Posted May 4, 2011 (edited) Something like this? >>Function & Example:expandcollapse popup#include <Array.au3> #include <Constants.au3> Local $aArray = _IPDetails() If @error = 0 Then Local $sData = 'Your IP Address: ' & $aArray[1] & @CRLF & _ 'Your Gateway Address: ' & $aArray[3] & @CRLF & _ 'You DNS Servers: ' & $aArray[4] MsgBox($MB_SYSTEMMODAL, '', $sData) EndIf _ArrayDisplay($aArray) 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] = [0] If IsObj($oColItems) Then For $oObjectItem In $oColItems If $oObjectItem.IPAddress(0) == @IPAddress1 Then $aReturn[0] = 4 $aReturn[1] = $oObjectItem.IPAddress(0) $aReturn[2] = $oObjectItem.MACAddress $aReturn[3] = $oObjectItem.DefaultIPGateway(0) $aReturn[4] = _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), ', ') ; You could use _ArrayToString() but I like creating my own Functions especially when I don't need alot of error checking. EndIf Next EndIf Return SetError($aReturn[0] = 0, 0, $aReturn) EndFunc ;==>_IPDetails Func _WMIArrayToString($aArray, $sDelimeter = '|') Local $sString = 'Not Available' If UBound($aArray) Then For $i = 0 To UBound($aArray) - 1 $sString &= $aArray[$i] & $sDelimeter Next $sString = StringTrimRight($sString, StringLen($sDelimeter)) EndIf Return $sString EndFunc ;==>_WMIArrayToString Edited March 21, 2013 by guinness zxtnt09 1 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
wowmarkb Posted May 4, 2011 Author Share Posted May 4, 2011 Thanks for you inputs. I really want to use the program I have and just add a couple of lines to make it display the Gateway Address and DNS Server Addresses after the IP Address. FYI- I have tried the command @IPAddress1 before and found that sometimes it was not accurate. (In my script after this line): $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1") (would this work if add something like this): $Gateway = StringRegExpReplace($Gateway, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1") $DNS = StringRegExpReplace($DNS, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*$", "\1") MsgBox(64, "Check IP Address", StringFormat("Your IP Address is: %s", $IP_Address, $Gateway, $DNS)) //////(I know nothing about programming). I'd like a window that pops open with: Your IP Address: xx.xx.xx.xx Your Gateway Address: xx.xx.xx.xx You DNS Servers: xx.xx.xx.xx , xx.xx.xx.xx (or something like that) Thanks. Link to comment Share on other sites More sharing options...
guinness Posted May 4, 2011 Share Posted May 4, 2011 (edited) Did you even try my Example? I have modified it a little to show a MsgBox, but I think I have given you enough to work with if I'm honest >>Example 1:expandcollapse popup#include <Array.au3> #include <Constants.au3> Local $aArray = _IPDetails() If @error = 0 Then Local $sData = 'Your IP Address: ' & $aArray[1] & @CRLF & _ 'Your Gateway Address: ' & $aArray[3] & @CRLF & _ 'You DNS Servers: ' & $aArray[4] MsgBox($MB_SYSTEMMODAL, '', $sData) EndIf _ArrayDisplay($aArray) 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] = [0] If IsObj($oColItems) Then For $oObjectItem In $oColItems If $oObjectItem.IPAddress(0) == @IPAddress1 Then $aReturn[0] = 4 $aReturn[1] = $oObjectItem.IPAddress(0) $aReturn[2] = $oObjectItem.MACAddress $aReturn[3] = $oObjectItem.DefaultIPGateway(0) $aReturn[4] = _WMIArrayToString($oObjectItem.DNSServerSearchOrder(), ', ') ; You could use _ArrayToString() but I like creating my own Functions especially when I don't need alot of error checking. EndIf Next EndIf Return SetError($aReturn[0] = 0, 0, $aReturn) EndFunc ;==>_IPDetails Func _WMIArrayToString($aArray, $sDelimeter = '|') Local $sString = 'Not Available' If UBound($aArray) Then For $i = 0 To UBound($aArray) - 1 $sString &= $aArray[$i] & $sDelimeter Next $sString = StringTrimRight($sString, StringLen($sDelimeter)) EndIf Return $sString EndFunc ;==>_WMIArrayToStringExample 2: the idea came from sahsanu for how to present the output.expandcollapse popup#include <Array.au3> #include <Constants.au3> Local $aArray = _IPDetails() If @error = 0 Then Local $sData = '' For $i = 1 To $aArray[0][0] $sData &= 'Description: ' & $aArray[$i][0] & @CRLF & 'IP Address: ' & $aArray[$i][1] & @CRLF & 'MAC: ' & _ $aArray[$i][2] & @CRLF & 'Default Gateway: ' & $aArray[$i][3] & @CRLF & 'DNS Servers: ' & $aArray[$i][4] & @CRLF & @CRLF Next $sData = StringTrimRight($sData, StringLen(@CRLF & @CRLF)) MsgBox($MB_SYSTEMMODAL, '', $sData) EndIf _ArrayDisplay($aArray) Func _IPDetails() Local $aReturn[1][5] = [[0, 5]], $iCount = 0 Local $oWMIService = ObjGet('winmgmts:{impersonationLevel = impersonate}!\\' & '.' & '\root\cimv2') Local $oColItems = $oWMIService.ExecQuery('Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True', 'WQL', 0x30) 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. Next ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] EndIf Return SetError($aReturn[0][0] = 0, 0, $aReturn) EndFunc ;==>_IPDetails Func _IsString($sString) If IsString($sString) = 0 Then $sString = 'Not Available' EndIf Return $sString EndFunc ;==>_IsString Func _WMIArrayToString($aArray, $sDelimeter = '|') Local $sString = 'Not Available' If UBound($aArray) Then For $i = 0 To UBound($aArray) - 1 $sString &= $aArray[$i] & $sDelimeter Next $sString = StringTrimRight($sString, StringLen($sDelimeter)) EndIf Return $sString EndFunc ;==>_WMIArrayToStringPlus, when you post code use the [autoit] tags and try to post the whole code instead of bits here and there. Edited March 21, 2013 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
wowmarkb Posted May 4, 2011 Author Share Posted May 4, 2011 Hi Guinness. Yes- that works great! OK, now I have another request. I tried it with a wireless adapter enabled. Is there a way in the message box to show both the Local Area Adapter and the Wireless Adapter addresses? Thanks. Link to comment Share on other sites More sharing options...
wowmarkb Posted May 4, 2011 Author Share Posted May 4, 2011 More for Guinness. Here is my total script - before your suggestion. How do I integrate your script into this little utility to make it all work? //////////Start #include <GUIConstants.au3> ; This script requires full Administrative rights #requireadmin #AutoIt3Wrapper_UseAnsi=y Opt("GUICoordMode",2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) Select Case @OSVersion = "WIN_VISTA" $Parent1 = GUICreate("GBON Tool", 180, 500, 600) GUICtrlCreateLabel("You have Windows Vista" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -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_XP" $Parent1 = GUICreate("GBON!", 165, 650, 780) GUICtrlCreateLabel("You have Windows XP" & @CRLF & "" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -120, 18, 100, 30) GUICtrlSetOnEvent(-1, "IP1Pressed") $release = GUICtrlCreateButton ("Release IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "ReleasePressed") $renew = GUICtrlCreateButton ("Renew IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "RenewPressed") $flush = GUICtrlCreateButton ("Flush DNS", -100, 18, 100) GUICtrlSetOnEvent(-1, "FlushPressed") $tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 18, 100) GUICtrlSetOnEvent(-1, "TCPIPPressed") $ping4 = GUICtrlCreateButton ("Ping Google", -100, 18, 100) GUICtrlSetOnEvent(-1, "Ping4Pressed") $inet = GUICtrlCreateButton ("Internet Options", -100, 18, 100) GUICtrlSetOnEvent(-1, "InetPressed") $serv = GUICtrlCreateButton ("Check Services", -100, 18, 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(10) Wend Func VerPressed() Run("winver") EndFunc ; Just idle around While 1 Sleep(10) Wend ; END Func IP1Pressed() $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 ; Just idle around While 1 Sleep(10) Wend ; END 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 ; Just idle around While 1 Sleep(10) Wend ; END 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 ; Just idle around While 1 Sleep(10) Wend ; END 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 ; Just idle around While 1 Sleep(10) Wend ; END 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 ; Just idle around While 1 Sleep(10) Wend ; END ;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 ; Just idle around While 1 Sleep(10) Wend ; END 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 ; Just idle around While 1 Sleep(10) Wend ; END Func InetPressed() Run("control inetcpl.cpl") WinWait("Internet Options", "", 5) EndFunc ; Just idle around While 1 Sleep(10) Wend ; END Func ServPressed() $File = @SystemDir & "\services.msc" Run(@SystemDir & "\mmc.exe " & $File) EndFunc ; Just idle around While 1 Sleep(10) Wend ; END 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 ///////////////End Link to comment Share on other sites More sharing options...
sahsanu Posted May 5, 2011 Share Posted May 5, 2011 (edited) Here is my total script - before your suggestion. How do I integrate your script into this little utility to make it all work? Hello, next time, please, put your source code between autoit or code tags. Here is your script with guinnes function. I didn't take care about your code but just removed all the no needed whiles you had there. expandcollapse popup#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_VISTA" $Parent1 = GUICreate("GBON Tool", 180, 500, 600) GUICtrlCreateLabel("You have Windows Vista" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -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_XP" $Parent1 = GUICreate("GBON!", 165, 650, 780) GUICtrlCreateLabel("You have Windows XP" & @CRLF & "" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -120, 18, 100, 30) GUICtrlSetOnEvent(-1, "IP1Pressed") $release = GUICtrlCreateButton ("Release IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "ReleasePressed") $renew = GUICtrlCreateButton ("Renew IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "RenewPressed") $flush = GUICtrlCreateButton ("Flush DNS", -100, 18, 100) GUICtrlSetOnEvent(-1, "FlushPressed") $tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 18, 100) GUICtrlSetOnEvent(-1, "TCPIPPressed") $ping4 = GUICtrlCreateButton ("Ping Google", -100, 18, 100) GUICtrlSetOnEvent(-1, "Ping4Pressed") $inet = GUICtrlCreateButton ("Internet Options", -100, 18, 100) GUICtrlSetOnEvent(-1, "InetPressed") $serv = GUICtrlCreateButton ("Check Services", -100, 18, 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, "_IPDetails()", $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(), ", ") ; 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 Edited May 5, 2011 by sahsanu Link to comment Share on other sites More sharing options...
wowmarkb Posted May 5, 2011 Author Share Posted May 5, 2011 Thanks sahsanu- you rock! My hat's off to you and all those before you who got me to this point It works just like I had hoped it would. Thanks again! Mark Link to comment Share on other sites More sharing options...
guinness Posted May 5, 2011 Share Posted May 5, 2011 Thanks sahsanu- you rock!Yeh, Thanks! I am little confused as to why you couldn't implement yourself? It appears you have a clear understanding of AutoIt. I would recommend having a look at Arrays >> http://www.autoitscript.com/wiki/Arrays as these can be a huge help with coding. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
wowmarkb Posted May 5, 2011 Author Share Posted May 5, 2011 Thanks. I have a micron of knowledge about programming. I can spell AutoIt but, I do not really understand arrays, variables, what the scripts are doing and all that. (I tried to learn Basic in the early 80's and looked at c# last year but, decided that I couldn't do it on my own.) 99.9% of my utility came from guys (& gals?) like you on this forum. Once I see the script- sometimes, I can kind of make out what it is doing and where I can make a change to make it do what I want. However, I mainly do cosmetic changes, though. Mark Link to comment Share on other sites More sharing options...
wowmarkb Posted May 6, 2011 Author Share Posted May 6, 2011 Is there a way in the IP Address message box, to show both the Local Area Adapter and the Wireless Adapter addresses? (In case a PC has both an Ethernet card & a Wireless card.) Thanks. Link to comment Share on other sites More sharing options...
guinness Posted May 6, 2011 Share Posted May 6, 2011 It's probably possible but I don't have enough time right now to write the code. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
sahsanu Posted May 8, 2011 Share Posted May 8, 2011 (edited) Is there a way in the IP Address message box, to show both the Local Area Adapter and the Wireless Adapter addresses? Below script will show all the network adapters with an ip address configured (I don't really know whether this is what you want): expandcollapse popup#include <GUIConstants.au3> ; This script requires full Administrative rights #requireadmin #AutoIt3Wrapper_UseAnsi=y Opt("GUICoordMode",2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) Select Case @OSVersion = "WIN_VISTA" $Parent1 = GUICreate("GBON Tool", 180, 500, 600) GUICtrlCreateLabel("You have Windows Vista" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -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_XP" $Parent1 = GUICreate("GBON!", 165, 650, 780) GUICtrlCreateLabel("You have Windows XP" & @CRLF & "" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -120, 18, 100, 30) GUICtrlSetOnEvent(-1, "IP1Pressed") $release = GUICtrlCreateButton ("Release IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "ReleasePressed") $renew = GUICtrlCreateButton ("Renew IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "RenewPressed") $flush = GUICtrlCreateButton ("Flush DNS", -100, 18, 100) GUICtrlSetOnEvent(-1, "FlushPressed") $tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 18, 100) GUICtrlSetOnEvent(-1, "TCPIPPressed") $ping4 = GUICtrlCreateButton ("Ping Google", -100, 18, 100) GUICtrlSetOnEvent(-1, "Ping4Pressed") $inet = GUICtrlCreateButton ("Internet Options", -100, 18, 100) GUICtrlSetOnEvent(-1, "InetPressed") $serv = GUICtrlCreateButton ("Check Services", -100, 18, 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(64, "IP Addresses",_IPDetails()) 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 $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 Edit: As per below guinness catch. Don't know why but autoit tags didn't like one of the "" on the StringRegExp functions. It is corrected now (I hope so). Edit2: No, it is not, really autoit tags don't like (dollar sign) and ' , they are eating them so I've put it between code tags that seems to work fine ;-) Edit3: Ahhhhhhhh, that is crazy, it fails after I refresh the page. I don't know how to solve this, please, in the code add (dollar sign)' at the pattern end on every StringRegExp function. Edited May 8, 2011 by sahsanu Link to comment Share on other sites More sharing options...
guinness Posted May 8, 2011 Share Posted May 8, 2011 sahsanu - Nice! Plus wowmarkb, I would recommend checking the SRE as they are missing " at the end, therefore it will fail on runtime! 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
wowmarkb Posted May 8, 2011 Author Share Posted May 8, 2011 sahsanu - Thanks but, it has errors- lines 101-105 (Lines 99-105 shown below). 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() //////////end When I do syntax check, it says this: >C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3" AutoIt3 Syntax Checker v1.54.8 Copyright © Tylo 2007 C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3(101,105) : ERROR: syntax error (illegal character) $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;, "\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3(107,105) : ERROR: syntax error (illegal character) $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;, "\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3(113,105) : ERROR: syntax error (illegal character) $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;, "\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3(119,105) : ERROR: syntax error (illegal character) $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;, "\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3(137,105) : ERROR: syntax error (illegal character) $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;, "\ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ C:\My Book Feb 2011\My GBON Tool\7 May\All IPs.au3 - 5 error(s), 0 warning(s) ////////////////end Guinness, I tried using an SRE tester online but, I am clueless as to how to make it work. I added a quote on the end of: line 101 like this: $IP_Address = StringRegExpReplace($IP_Address, "(?i)(?s).*IP.*?(\d+\.\d+\.\d+\.\d+).*{:content:}quot;, "\1")" ...but that didn't work. I did change a couple of lines to the previous script that opens a DOS window and displays all the ipconfig info which is OK. It would be nice to have a message box open and give only the IP Address, Gateway, & DNS Servers for all Local Area Adapters & Wireless Adapters so that it won't be information overload to for users when they hit the Check Addresses button, that's all: ////////////start #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, 500, 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, 18, 100, 30) GUICtrlSetOnEvent(-1, "IP1Pressed") $release = GUICtrlCreateButton ("Release IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "ReleasePressed") $renew = GUICtrlCreateButton ("Renew IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "RenewPressed") $flush = GUICtrlCreateButton ("Flush DNS", -100, 18, 100) GUICtrlSetOnEvent(-1, "FlushPressed") $tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 18, 100) GUICtrlSetOnEvent(-1, "TCPIPPressed") $ping4 = GUICtrlCreateButton ("Ping Google", -100, 18, 100) GUICtrlSetOnEvent(-1, "Ping4Pressed") $inet = GUICtrlCreateButton ("Internet Options", -100, 18, 100) GUICtrlSetOnEvent(-1, "InetPressed") $serv = GUICtrlCreateButton ("Check Services", -100, 18, 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() $CMD = "ipconfig /all" RunWait(@ComSpec & " /k " & $CMD, @WindowsDir, @SW_SHOW) 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 /////////////////end Thanks sahsanu & guinness for your continued help. Link to comment Share on other sites More sharing options...
guinness Posted May 8, 2011 Share Posted May 8, 2011 Please please when you post code use the expandcollapse popup[/autoit][/b] tags. I have fixed the code, but I highly suggest firstly comparing the error version with the update to see what I changed and secondly looking through the Help File, because I know you have taken code from here and there but in the long run it will cause problems sticking bits and pieces together. Also the errors were quite clear in the SciTE output screen. [b]FIXED:[/b] [autoit]#include <GUIConstants.au3> ; This script requires full Administrative rights #requireadmin #AutoIt3Wrapper_UseAnsi=y Opt("GUICoordMode",2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) MsgBox(64, "IP Addresses",_IPDetails()) Exit Select Case @OSVersion = "WIN_VISTA" $Parent1 = GUICreate("GBON Tool", 180, 500, 600) GUICtrlCreateLabel("You have Windows Vista" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -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_XP" $Parent1 = GUICreate("GBON!", 165, 650, 780) GUICtrlCreateLabel("You have Windows XP" & @CRLF & "" & @CRLF & "Wait 10 sec. after clicking", 25, 20) GUISetBkColor(0x33CCCC) ; set color GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $ip1 = GUICtrlCreateButton ("Check IP Address", -120, 18, 100, 30) GUICtrlSetOnEvent(-1, "IP1Pressed") $release = GUICtrlCreateButton ("Release IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "ReleasePressed") $renew = GUICtrlCreateButton ("Renew IP", -100, 18, 100) GUICtrlSetOnEvent(-1, "RenewPressed") $flush = GUICtrlCreateButton ("Flush DNS", -100, 18, 100) GUICtrlSetOnEvent(-1, "FlushPressed") $tcpip = GUICtrlCreateButton ("TCP/IP Winsock", -100, 18, 100) GUICtrlSetOnEvent(-1, "TCPIPPressed") $ping4 = GUICtrlCreateButton ("Ping Google", -100, 18, 100) GUICtrlSetOnEvent(-1, "Ping4Pressed") $inet = GUICtrlCreateButton ("Internet Options", -100, 18, 100) GUICtrlSetOnEvent(-1, "InetPressed") $serv = GUICtrlCreateButton ("Check Services", -100, 18, 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(64, "IP Addresses",_IPDetails()) 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", 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+).*{: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 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 Note: I updated my previous _IPDetails() code. 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 8, 2011 Share Posted May 8, 2011 (edited) A quick question if I may while on the topic, Is it possible to get an adapters 'name' as in "Local Area Connection" rather than the Description - OR is there a way to disable/enable and set ip fields using the adapter Description via the WMI as in the example? (i'm trying to make a full basic/advanced ipconfig UI which has the option of saving presets, which would obviously need these functions and I haven't been able to find any 'stable' ways of doing it) Edited May 8, 2011 by katoNkatoNK Link to comment Share on other sites More sharing options...
guinness Posted May 8, 2011 Share Posted May 8, 2011 (edited) Perhaps this?Func _GetNetworkID($sAdapter) Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2") Local $oColItems = $oWMIService.ExecQuery('Select * From Win32_NetworkAdapter Where Name = "' & $sAdapter & '"', "WQL", 0x30) If IsObj($oColItems) Then For $oObjectItem In $oColItems Return $oObjectItem.NetConnectionID Next EndIf Return SetError(1, 0, "Unknown") EndFunc ;==>_GetNetworkIDExample 3:expandcollapse popup#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 & "Connection Name: " & _GetNetworkID($aArray[$A][0]) & @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][5] = [[0, 5]] 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. Next ReDim $aReturn[$aReturn[0][0] + 1][$aReturn[0][1]] Return $aReturn EndIf Return SetError(1, 0, $aReturn) EndFunc ;==>_IPDetails Func _GetNetworkID($sAdapter) Local $oWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & "." & "\root\cimv2") Local $oColItems = $oWMIService.ExecQuery('Select * From Win32_NetworkAdapter Where Name = "' & $sAdapter & '"', "WQL", 0x30) If IsObj($oColItems) Then For $oObjectItem In $oColItems Return $oObjectItem.NetConnectionID Next EndIf Return SetError(1, 0, "Unknown") EndFunc ;==>_GetNetworkID 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 ;==>_WMIArrayToStringNote: For some reason its a little slow, but I'm not a WMI Expert! Edited May 16, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
katoNkatoNK Posted May 8, 2011 Share Posted May 8, 2011 Thank you for the quick reply I actually forgot about 'ConnectionID' after having a look through WMI parameters, but a full working example is much appreciated!! I do have another question..for interests sake Is it possible to do all the functions as if i were to do it in a command line such as the 'netsh' parameters and the other relevant adapter functions in WMI or something else without needing a mass of code? If not what would be the most reliable way of doing all the 'netsh' commands or the like, if other than cmd prompt? (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 ) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now