rvn Posted July 22, 2012 Posted July 22, 2012 (edited) Attention : for beginner only Not everyone master Regular Expression right.A function that run ipconfig in background, then parsing it to simple ini file.expandcollapse popupIpconfig_to_ini() Func Ipconfig_to_ini($pLogName = "", $pLogDir = "", $pIniFileTarget = "") Local $SECTION,$KEY,$VALUE,$i If $pLogName = "" Then $pLogName = "ipconfig.log" If $pLogDir = "" Then $pLogDir = @ScriptDir If $pIniFileTarget = "" Then $pIniFileTarget = @ScriptDir & "ipconfig.ini" FileDelete($pIniFileTarget) RunWait(@Comspec & " /c ipconfig /all > " & $pLogName, $pLogDir , @SW_HIDE) If @error Then Return 0 Local $file = FileOpen($pLogDir & "" & $pLogName, 0) Local $line ; Check if file opened for reading OK If $file = -1 Then Return 0 EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;MsgBox(0, "Line read:", $line) If $line = "" Then Else If StringLeft($line,1) = " " Then ;key If StringLeft($line,9) = " " Then ;value $VALUE = IniRead($pIniFileTarget,$SECTION,$KEY,"") ;ConsoleWrite($VALUE & @CRLF) $VALUE = $VALUE & " " & StringStripWS($line,1+2) ;ConsoleWrite($VALUE & @CRLF) Else ;key If StringRegExp($line,":") = 1 Then ; [key : value] $string = StringSplit($line,":") $KEY = StringStripWS($string[1],1+2) $KEY = StringReplace($KEY,".","") If $string[0] = 2 Then $VALUE = StringStripWS($string[2],1+2) Else $VALUE = "" For $i = 2 To $string[0] $VALUE = $VALUE & $string[$i] & ":" ;ConsoleWrite($VALUE & @CRLF) Next $VALUE = StringTrimRight($VALUE,1) EndIf Else $VALUE = IniRead($pIniFileTarget,$SECTION,$KEY,"") ;ConsoleWrite($VALUE & @CRLF) $VALUE = $VALUE & " " & StringStripWS($line,1+2) ;ConsoleWrite($VALUE & @CRLF) EndIf EndIf IniWrite($pIniFileTarget,$SECTION,$KEY,$VALUE) Else ; section $line = StringStripWS($line,1 +2) If StringRight($line,1) = ":" Then $line = StringTrimRight($line,1) $SECTION = $line EndIf EndIf Wend FileClose($file) FileDelete($pLogDir & "" & $pLogName) Return 1 EndFuncSimple but work,,, at least for me Note : more than one value, saved in ini with space delimiter (example : multiple DNS Servers).Thanx Note : Scroll down for updated script! Edited July 22, 2012 by rvn
guinness Posted July 22, 2012 Posted July 22, 2012 (edited) I like challenges of this description so I therefore decided to revise your code by removing the need to write the StdRead output to a file as well as improving the structure of the syntax. Also you use StringRegExp in your example when a simple StringInStr would have been fine. expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <Constants.au3> ConsoleWrite(_IPConfig_To_INI(@ScriptDir & '\INIFile.ini') & @CRLF) ; Returns the contents of the INI file. Func _IPConfig_To_INI($sINIFilePath) Local $iPID = Run(@ComSpec & ' /c ipconfig /all', @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = '' While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd If FileExists($sINIFilePath) = 0 Then $sINIFilePath = @ScriptDir & '\INIFile.ini' Else FileClose(FileOpen($sINIFilePath, 2)) ; Destroy the previous contents. EndIf Local $aArray = StringSplit(StringStripCR($sOutput), @LF), $iSplitSection = 0, $sData = '', $sKey = '', $sSection = '', $sValue = '' $sOutput = '' ; Empty the StdoutRead variable. For $i = 1 To $aArray[0] If StringStripWS($aArray[$i], 8) = '' Then ContinueLoop EndIf If StringLeft($aArray[$i], 1) = ' ' Then ; Value $iSplitSection = StringInStr($aArray[$i], ':', 2) ; Find the first location of ':' $sKey = StringStripWS(StringLeft(StringLeft($aArray[$i], $iSplitSection), StringInStr($aArray[$i], '.', 2) - 1), 3) ; INI Key $sValue = StringStripWS(StringTrimLeft($aArray[$i], $iSplitSection), 3) ; INI Value If StringStripWS($sKey, 8) = '' Then $sData = StringTrimRight($sData, StringLen(@LF)) & ';' & $sValue & @LF ; For those values that are DNS servers. I chose to use ';' as the delimiter. ContinueLoop EndIf If $sValue = '' Or $sValue = '::' Then ; If the value is blank or '::' then replace with the value of '(None)'. $sValue = '(None)' EndIf $sData &= $sKey & '=' & $sValue & @LF ; Add the key and value to the following section. Else ; Section If $sSection <> '' And $sData <> '' Then IniWriteSection($sINIFilePath, $sSection, $sData) ; Write the section to the INI file. $sOutput &= '[' & $sSection & ']' & @LF & $sData ; Add to the return variable. $sData = '' EndIf $sSection = StringStripWS($aArray[$i], 3) $sSection = StringTrimRight($sSection, Number(StringRight($sSection, 1) = ':')) ; Section EndIf Next Return $sOutput EndFunc ;==>_IPConfig_To_INI Edited June 11, 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
rvn Posted July 22, 2012 Author Posted July 22, 2012 (edited) Nicely executed guinness,,, more effisient script there That StringRegExp,,, i know my fault This line inside your function, confius me little bit $sINIFilePath = @ScriptDir & 'INIFile.ini'And here, i change your script for my need,,, i'll keep it ... Hope someone also benefit from it.expandcollapse popup#include ;_IPConfig_To_INI("C:test.ini") _IPConfig_To_INI() Func _IPConfig_To_INI($sINIFilePath = "") Local $iPID = Run(@ComSpec & ' /c ipconfig /all', @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = '' While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd ;added If $sINIFilePath = "" Then $sINIFilePath = @ScriptDir & 'Ipconfig.ini' FileDelete($sINIFilePath) Local $aArray = StringSplit(StringStripCR($sOutput), @LF), $iSplitSection = 0, $sData = '', $sKey = '', $sSection = '', $sValue = '' $sOutput = '' ; Empty the StdoutRead variable. For $i = 1 To $aArray[0] If StringStripWS($aArray[$i], 8) = '' Then ContinueLoop EndIf If StringLeft($aArray[$i], 1) = ' ' Then ; Value $iSplitSection = StringInStr($aArray[$i], ':', 2) ; Find the first location of ':' $sKey = StringStripWS(StringLeft(StringLeft($aArray[$i], $iSplitSection), StringInStr($aArray[$i], '.', 2) - 1), 3) ; INI Key $sValue = StringStripWS(StringTrimLeft($aArray[$i], $iSplitSection), 3) ; INI Value If StringStripWS($sKey, 8) = '' Then $sData = StringTrimRight($sData, StringLen(@LF)) & ';' & $sValue & @LF ; For those values that are DNS servers. I chose to use ';' as the delimiter. ContinueLoop EndIf $sData &= $sKey & '=' & $sValue & @LF ; Add the key and value to the following section. Else ; Section If $sSection <> '' And $sData <> '' Then IniWriteSection($sINIFilePath, $sSection, $sData) ; Write the section to the INI file. $sOutput &= '[' & $sSection & ']' & @LF & $sData ; Add to the return variable. $sData = '' EndIf $sSection = StringStripWS($aArray[$i], 3) $sSection = StringTrimRight($sSection, Number(StringRight($sSection, 1) = ':')) ; Section EndIf Next Return $sOutput EndFunc ;==>_IPConfig_To_INI Edited July 22, 2012 by rvn
guinness Posted July 22, 2012 Posted July 22, 2012 (edited) That line simply means if the filepath passed doesn't exist then create a file called INIFile.ini in the script/exe location. Or am I missing something? Edit: Try using FileExists instead of checking for a blank string. Edited July 22, 2012 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
rvn Posted July 22, 2012 Author Posted July 22, 2012 Yup, now i know... I'll leave the old script... You know,,, beginner thing Thanx btw
firsttimer Posted August 4, 2012 Posted August 4, 2012 (edited) This code "#include" should be "#include <Constants.au3>", rvn. BTW, nice scripts both of you. Thanks Edited August 4, 2012 by firsttimer
guinness Posted August 4, 2012 Posted August 4, 2012 This code "#include" should be "#include <Constants.au3>", rvn. BTW, nice scripts both of you. ThanksI think this is the forum more than anything else. 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
HSZ Posted June 11, 2013 Posted June 11, 2013 Hi There! I am quite new to AutoIT and I have a problem regarding this script and was wondering if anybody could help me out with it. First of all, this script is exactly what i need but the thing is: I have 2 network adapters and the script refuses to parse the second one (which is the active one) into the INI file (although the array has all the data). =( I was trying to solve this for quite some time now but i just can't seem to find the problem. Could anybody give me some advise here, please? Thanks in advance!
BrewManNH Posted June 11, 2013 Posted June 11, 2013 (edited) There's a mistake in all the posted code in this thread, I'm not sure if it's the forum stripping characters or just cut and paste errors, but everywhere that you see "@ScriptDir & 'INIFile.ini'" it should be "@ScriptDir & 'INIFile.ini'". Edited June 11, 2013 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
guinness Posted June 11, 2013 Posted June 11, 2013 That's the Forum. 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
HSZ Posted June 12, 2013 Posted June 12, 2013 Hi again, thaks for the answer but unfortunately that doesn't solve the problem because i used a different path anyways. The problem is the [Windows-IP-Configuration] and the [Ethernet-Adapter LAN Connection 2] sections do get written into the INI file, but after the that the script does not write the other Ethernet-Adapter to the INI file. I looked at the whole loop and it seems that although the strings get striped and formated in the right way (although im not entierly sure about the name of the third section itself), the last INIWriteSection at the end of the script is just not executed it seems. Any thoughts on this are, again, really appreciated
guinness Posted June 12, 2013 Posted June 12, 2013 Who's code did you try? Mine works on Windows 7 x64. 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
HSZ Posted June 12, 2013 Posted June 12, 2013 Hey there, found it. The problem was that the Loop exited and terminated before the last Section was written, although the strings were striped and formated etc. I dont know why it did, but thats what happened there. I found a simple workaround: In the final loop im checking if the last section was written and if it wasn't I'll just write it. For this purpose I'm using a new IF/ELSE clause just at the beginning of the Loop with the original Code beeing the ELSE clause. It's probably not the most beautiful thing to do but hey, it works. Here's what I did: expandcollapse popupFunc _IPConfig_To_INI($sINIFilePath) Local $iPID = Run(@ComSpec & ' /c ipconfig /all', @SystemDir, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD), $sOutput = '' While 1 $sOutput &= StdoutRead($iPID) If @error Then ExitLoop EndIf WEnd If FileExists($sINIFilePath) = 0 Then $sINIFilePath = $BackupDir & 'IPConfig.ini' Else FileClose(FileOpen($sINIFilePath, 2)) ; Destroy the previous contents. EndIf Local $aArray = StringSplit(StringStripCR($sOutput), @LF), $iSplitSection = 0, $sData = '', $sKey = '', $sSection = '', $sValue = '' $sOutput = '' ; Empty the StdoutRead variable. For $i = 1 To $aArray[0] If $i = $aArray[0] And IniRead($sINIFilePath, $sSection, $sKey, "Not written yet") = "Not written yet" Then ; Write the last Section at the End of the script if there are 2 or more Network Adapters IniWriteSection($sINIFilePath, $sSection, $sData) ; Write the section to the INI file. $sOutput &= '[' & $sSection & ']' & @LF & $sData ; Add to the return variable. $sData = '' Else If StringStripWS($aArray[$i], 8) = '' Then ContinueLoop EndIf If StringLeft($aArray[$i], 1) = ' ' Then ; Value $iSplitSection = StringInStr($aArray[$i], ':', 2) ; Find the first location of ':' $sKey = StringStripWS(StringLeft(StringLeft($aArray[$i], $iSplitSection), StringInStr($aArray[$i], '.', 2) - 1), 3) ; INI Key $sValue = StringStripWS(StringTrimLeft($aArray[$i], $iSplitSection), 3) ; INI Value If StringStripWS($sKey, 8) = '' Then $sData = StringTrimRight($sData, StringLen(@LF)) & ';' & $sValue & @LF ; For those values that are DNS servers. I chose to use ';' as the delimiter. ContinueLoop EndIf If $sValue = '' Or $sValue = '::' Then ; If the value is blank or '::' then replace with the value of '(None)'. $sValue = '(None)' EndIf $sData &= $sKey & '=' & $sValue & @LF ; Add the key and value to the following section. Else ; Section If $sSection <> '' And $sData <> '' Then IniWriteSection($sINIFilePath, $sSection, $sData) ; Write the section to the INI file. $sOutput &= '[' & $sSection & ']' & @LF & $sData ; Add to the return variable. $sData = '' EndIf $sSection = StringStripWS($aArray[$i], 3) $sSection = StringTrimRight($sSection, Number(StringRight($sSection, 1) = ':')); Section EndIf EndIf Next Return $sOutput EndFunc ;==>_IPConfig_To_INI Thanks for your answers guys
guinness Posted June 12, 2013 Posted June 12, 2013 If it works for you then great. 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
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