Laymanball Posted October 5, 2011 Share Posted October 5, 2011 (edited) Using for create file INI. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("IniFlieCreate", 250, 226, 192, 124) GUICtrlCreateLabel("Filename:", 32, 16, 49, 17) $Input1 = GUICtrlCreateInput("Input1", 88, 16, 145, 21) GUICtrlCreateLabel("Sectionname:", 16, 56, 69, 17) $Input2 = GUICtrlCreateInput("Input2", 88, 56, 145, 21) GUICtrlCreateLabel("Keyname:", 32, 96, 51, 17) $Input3 = GUICtrlCreateInput("Input3", 88, 96, 145, 21) GUICtrlCreateLabel("Valuename:", 24, 136, 62, 17) $Input4 = GUICtrlCreateInput("Input4", 88, 136, 145, 21) $Button1 = GUICtrlCreateButton("Build", 88, 184, 75, 25, $WS_GROUP) GUISetState(@SW_SHOW) _ScriptIn() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 If Not FileExists(GUICtrlRead($Input1))Then _IniFileCreate() EndSwitch WEnd ;=============Udf IniFileCreate Library Function============ Func _IniFileCreate() Dim $aiArray[2] $aiArray[0]="["&GUICtrlRead($Input2)&"]" $aiArray[1]=GUICtrlRead($Input3)&"="&GUICtrlRead($Input4) $iOutput="" For $Element In $aiArray $iOutput=$iOutput&$Element&@CRLF Next FileWrite(GUICtrlRead($Input1), $iOutput) EndFunc ;=========================================================== Func _ScriptIn() GUICtrlSetData($Input1, "SettingTest.ini") GUICtrlSetData($Input2, "Section1") GUICtrlSetData($Input3, "Key1") GUICtrlSetData($Input4, "Value1") EndFuncORNo,GUI;================IniFileCreate Library Function================ Global $Ininame="SettingTest.ini", $sSection="[Section1]" Global $sKey="Key1", $sValue="Value1" Func _IniFileCreate($Ininame, $sSection, $sKey, $sValue) Dim $aiArray[2] $aiArray[0]="["&$sSection&"]" $aiArray[1]=$sKey&"="&$sValue $iOutput="" For $Element In $aiArray $iOutput=$iOutput&$Element&@CRLF Next FileWrite($Ininame, $iOutput) Return 0 EndFunc ;==========================Example============================= _IniFileCreate("SettingTest2.ini", "Section2", "Key2", "Value2") Edited October 5, 2011 by Laymanball My Sample Script Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html Link to comment Share on other sites More sharing options...
Laymanball Posted October 5, 2011 Author Share Posted October 5, 2011 (edited) IniGetKeyname Library Function Global $Ininame, $sSection, $sKey, $sValue ;========IniFileCreate Library Include Function========= Func _IniFileCreate($Ininame, $sSection, $sKey, $sValue) Dim $aiArray[2] $aiArray[0]="["&$sSection&"]" $aiArray[1]=$sKey&"="&$sValue Local $Element Local $iOutput="" For $Element In $aiArray $iOutput=$iOutput&$Element&@CRLF Next $cErr = FileWrite($Ininame, $iOutput) If($cErr=0)Then Return SetError(1, 0, 0) Return 0 EndFunc ;=========IniGetKeyname Library Function========= Global $Ininame Func _IniGetKeyname($Ininame) Local $fOpen=FileOpen($Ininame, 0) Local $rLine=FileReadLine($fOpen, 2) Local $sSplit = StringSplit($rLine, "=") If Not IsArray($sSplit)Then Return SetError(1, 0, 0) Return $sSplit[1] EndFunc ;===============Sample Script================= If Not FileExists("SampleTest3.ini")Then _IniFileCreate("SampleTest3.ini", "Section3", "Picture", "Logo.jpg") EndIf MsgBox(0, "", "Keyname="&_IniGetKeyname("SampleTest3.ini"))IniGetValuename Library FunctionGlobal $Ininame, $sSection, $sKey, $sValue ;========IniFileCreate Library Include Function========= Func _IniFileCreate($Ininame, $sSection, $sKey, $sValue) Dim $aiArray[2] $aiArray[0]="["&$sSection&"]" $aiArray[1]=$sKey&"="&$sValue Local $Element Local $iOutput="" For $Element In $aiArray $iOutput=$iOutput&$Element&@CRLF Next $cErr = FileWrite($Ininame, $iOutput) If($cErr=0)Then Return SetError(1, 0, 0) Return 0 EndFunc ;=========IniGetValuename Library Function========= Global $Ininame Func _IniGetValuename($Ininame) Local $fOpen=FileOpen($Ininame, 0) Local $rLine=FileReadLine($fOpen, 2) Local $sSplit = StringSplit($rLine, "=") If Not IsArray($sSplit)Then Return SetError(1, 0, 0) Return $sSplit[2] EndFunc ;===============Sample Script================= If Not FileExists("SampleTest3.ini")Then _IniFileCreate("SampleTest3.ini", "Section3", "Picture", "Logo.jpg") EndIf MsgBox(0, "", "Valuename="&_IniGetValuename("SampleTest3.ini"));---------------------------------------------------------------------Run App from File.iniGlobal $Ininame, $sSection, $sKey, $sValue ;========IniFileCreate Library Include Function========= Func _IniFileCreate($Ininame, $sSection, $sKey, $sValue) Dim $aiArray[2] $aiArray[0]="["&$sSection&"]" $aiArray[1]=$sKey&"="&$sValue Local $Element Local $iOutput="" For $Element In $aiArray $iOutput=$iOutput&$Element&@CRLF Next $cErr = FileWrite($Ininame, $iOutput) If($cErr=0)Then Return SetError(1, 0, 0) Return 0 EndFunc ;=========IniGetValuename Library Function========= Global $Ininame Func _IniGetValuename($Ininame) Local $fOpen=FileOpen($Ininame, 0) Local $rLine=FileReadLine($fOpen, 2) Local $sSplit = StringSplit($rLine, "=") If Not IsArray($sSplit)Then Return SetError(1, 0, 0) Return $sSplit[2] EndFunc ;===============Sample Script================= If Not FileExists("SampleTest3.ini")Then _IniFileCreate("SampleTest3.ini", "Section3", "App", "Calc.exe") EndIf ShellExecute(_IniGetValuename("SampleTest3.ini")) Edited October 5, 2011 by Laymanball My Sample Script Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html Link to comment Share on other sites More sharing options...
BrewManNH Posted October 5, 2011 Share Posted October 5, 2011 I'm not sure if you're aware of this, but AutoIt has a collection of functions that deal with .ini files already built in. See the help file for the functions that start with INI for reading and writing to them. 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 Link to comment Share on other sites More sharing options...
Laymanball Posted October 5, 2011 Author Share Posted October 5, 2011 (edited) BrewManNH Thanks.'re Sorry too. If I write the code correctly. I will stop writing now. Edited October 5, 2011 by Laymanball My Sample Script Download: VistaDesktopIconsChangerForXp.au3 (Com,Doc and Bin only) http://www.4shared.com/rar/NMHYL5Igba/VistaDesktopIconsChangerForXp_.html VistaDesktopIconsChangerForXp.exe (Resources) http://www.4shared.com/rar/nzs7Mb1gba/VistaDesktopIconsChangerForXp_.html 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