Kupex INI Tools 1.0



Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here



ActiveX Control

The Kupex INI Tools 1.0 ActiveX control allows you to easily read and edit INI files.

INI files (files ending with .ini) were used by a lot of programs in Windows 3.1 (with some using the registry), but since Windows 95 has been available, many more programs use the registry to save their settings instead.  Your program should use VB6's GetSetting, SaveSetting and DeleteSetting Statements to store settings, but you may need to read an INI file, system.ini for example.  If you need to use INI files, you should use this control.  There are also API commands to edit INI files.  INI files are in this format:



You can't have two sections with the same name, but you can have keys with the same name but only if they are in different sections.

This control was available from the Kupex website that does not seem to exist anymore.  You can download the control from my website instead.

The examples on this page will use INI code in a made up file called C:\Cars.ini, which looks like this:





Shows the about box:

About Box
About Box


SectionName As String, KeyName As String, FileName As String

Use this method to get information by specifying the section, key and filename.

MsgBox INITool1.GetFromINI("Fiesta", "Colour", "C:\Cars.ini") 'Returns "Green"
MsgBox INITool1.GetFromINI("Granada", "Doors", "C:\Cars.ini") 'Returns "5"
MsgBox INITool1.GetFromINI("Granada", "Mileage", "C:\Cars.ini") 'Returns "[NOT FOUND]"


SectionName As String, FileName As String

Returns the first line of a section.  This seems pointless to me.

MsgBox INITool1.GetINISection("Fiesta", "C:\Cars.ini") 'Returns "Make=Ford"
MsgBox INITool1.GetINISection("Maestro", "C:\Cars.ini") 'Returns ""


Text As String, SectionName As String, KeyName As String, FileName As String

Edits a key or creates a section and key if they don't exist.

INITool1.WriteToINI "Red", "Fiesta", "Colour", "C:\Cars.ini" 'Edits the 'Colour' key in the 'Fiesta' section
INITool1.WriteToINI "Blue", "Maestro", "Colour", "C:\Cars.ini" 'Creates the 'Maestro' section and the 'Colour' key in that section
INITool1.WriteToINI "No", "Granada", "CD Player", "C:\Cars.ini" 'Creates the 'CD Player' key in the 'Granada' section


Text As String, KeyName As String, FileName As String

Creates text that looks like this in the file:


Existing sections are replaced and you can't edit the key.  Again, this seems pointless and you could also lose a whole section of data.  Also, Text should be KeyName and KeyName should be SectionName.

INITool1.WriteToINISection "Colour", "Fiesta", "C:\Cars.ini"

Archived Comments

From: Martyn
Date: Thursday, September 29, 2005 at 09:31:37

why have another control when you can use API?

Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

WritePrivateProfileString "Section", "Key", "This is the value", "test.ini"

dim ret as string
length as string
ret = string(255,0)''alocate space for the value

length = GetPrivateProfileString("Section", "Key", "Default", ret, 255, "test.ini") 

ret = left(ret,length)

easy as pie!

From: Bill
Date: Wednesday, June 30, 2004 at 20:58:54
Comments: Thank you! This is what I needed!
From: Reuben
Date: Thursday, May 13, 2004 at 14:38:36
Comments: What a beautiful thing!  I am an amature VBr so when I entered your examples directly, they did not work.  I got this example from Article/ArticleID/4729/4729.html - Set FileObject = CreateObject("INITools.INITool")
MyINIEntry = FileObject.GetFromINI("Header", "Key", File).  It seems to work quite well.  Thank you for helping out.


From: Andrew
Date: Thursday, April 22, 2004 at 13:19:36
Comments: Thankyou! Been searching for 2 days for a simple, easy to use ActiveX to write INI's
From: Jonno
Date: Thursday, February 5, 2004 at 18:15:59
Comments: Brilliant, I'm amazed it wasn't in te default VB tools!
From: Dave
Date: Saturday, May 31, 2003 at 21:57:56
Comments: Fantastic! thank you, precisely what I was looking for!!!!!

Martin Allen 1999 - 2011.  Last updated Wednesday 10 August 2011 07:35:51 PM +0100.