Solved

Adding changing ini files

Posted on 1999-01-17
1
137 Views
Last Modified: 2010-05-03
Hi,

I want to get my VB 5.0 program to open win.ini, search through the text to
see if there the program is already listed (useful for removal latter on)
and then add the run = c:\windows\myapp.exe.


Cheers Warren

0
Comment
Question by:isec1
1 Comment
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 1469053
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

Public Function ReadFromINI(ByVal pSection As String, _
                            ByVal pKey As String, _
                            ByVal pDefault As String, _
                            ByVal pPath As String _
                           ) As String
'pSection is the section in the .ini in which you search
'pKey is the word on the left side of the equal sign (=)
'pDefault will be return if the key is not find in the section
'pPath is the file you want to open (with the path)

'strapppl = ReadFromINI("Application", "App1", "Default_Value", "Win.INI")
Dim lngReturn As Long
Dim strReturn As String

    strReturn = String$(200, 0)
    lngReturn = GetPrivateProfileString(pSection, pKey, pDefault, strReturn, Len(strReturn), pPath)
    ReadFromINI = Left$(strReturn, lngReturn)
End Function


0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question