Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INI file 1

Status
Not open for further replies.

irenavassilia

Programmer
Jun 19, 2007
101
Hi All,

I have a program GLAccounts which on button click is suppose to pull up another VB application - Notes.exe.
I copied these programs over to my clients computer.

The problem is I have an INI file for the configuration of the database and a path for where to pull the Notes.exe program. On my machine everything is working fine and its reading the path from the ini file without any issues, however on my clients computer it is not reading the path because when i created a msgbox to display the path its empty "".

Very confused as to why its not reading the path on my clients computer. Hopefully someone can help me.

Thank you.

Regards,
 
Please, someone help, still having the same problem its not reading the ini file but it gets the ini file directory with the ini file.. why isnt it reading it on my clients computer?
Any help will be GREATLY appreaciated I will donate as soon as i get paid! *sigh*

Thanks.
 
This code gets the ini file:


Code:
Sub InitializeDatabaseSettings()

'{{EA
On Error GoTo ErrorHandler
'}}EA

Dim bolConfigFileExists As Boolean

Set pobjFileS = New FileSystemObject

pstrConfigIniPath = App.Path & "\Bin\" & App.EXEName & ".ini"

MsgBox "This is the path of the ini file" & pstrConfigIniPath

bolConfigFileExists = pobjFileS.FileExists(pstrConfigIniPath)

MsgBox bolConfigFileExists

If bolConfigFileExists = False Then
    Call modErrorHandler.ErrorTrap("999", "The System will shutdown. Cannot find the config file in the following path: " & pstrConfigIniPath & ". Please contact Balgord immediately with this issue.", pstrProjectTitle, "Main", "modMain")
    Call CloseProject
    End
End If

Call GetDatabaseSettings(bolConfigFileExists)

pstrConnectionString = "DSN=" & pstrDatabaseName & ";Uid=;Pwd="

'{{EA
ErrorHandler_Exit:
    Screen.MousePointer = 0
    Exit Sub
ErrorHandler:
    Call modErrorHandler.ErrorTrap(Err.Number, Err.Description, Err.Source, "InitializeDatabaseSettings", "modMain")
    GoTo ErrorHandler_Exit
'}}EA

End Sub

This is where it reads the ini file:

Sub GetDatabaseSettings(vbolConfigFileExists As Boolean)

'{{EA
On Error GoTo ErrorHandler
'}}EA

Dim strDate As String

Dim strTemp As String
Dim strSection As String

Dim objINI As New stsTools.clsToolsIni

If vbolConfigFileExists = False Then Exit Sub
MsgBox "Config File Exists"
strSection = "Database"
ptypDBSettings.pstrProvider = UCase(objINI.strGetFromIni(strSection, "Provider", pstrConfigIniPath))
ptypDBSettings.pstrServerName = UCase(objINI.strGetFromIni(strSection, "ServerName", pstrConfigIniPath))
ptypDBSettings.pstrDatabaseName = UCase(objINI.strGetFromIni(strSection, "DatabaseName", pstrConfigIniPath))

MsgBox "Database read from ini file"

strSection = "ACCPAC_Database"
ptypDBSettings.pstrProvider_ACCPAC = UCase(objINI.strGetFromIni(strSection, "Provider", pstrConfigIniPath))
ptypDBSettings.pstrServerName_ACCPAC = UCase(objINI.strGetFromIni(strSection, "ServerName", pstrConfigIniPath))
ptypDBSettings.pstrDatabaseName_ACCPAC = UCase(objINI.strGetFromIni(strSection, "DatabaseName", pstrConfigIniPath))
MsgBox "ACCPAC_Database read from ini file"

strSection = "ACCPAC"
ptypACCPACSettings.pstrVersion = UCase(objINI.strGetFromIni(strSection, "Version", pstrConfigIniPath))
ptypACCPACSettings.pstrAPPID = UCase(objINI.strGetFromIni(strSection, "APPID", pstrConfigIniPath))
ptypACCPACSettings.pstrProgramName = UCase(objINI.strGetFromIni(strSection, "ProgramName", pstrConfigIniPath))

MsgBox "ACCPAC section read from ini file"

strSection = "Project"
pstrProjectTitle = UCase(objINI.strGetFromIni(strSection, "Title", pstrConfigIniPath))

strSection = "Preference"
strTemp = UCase(objINI.strGetFromIni(strSection, "ShowSplashScreen", pstrConfigIniPath))
If strTemp = True Or strTemp = False Then
    pbolShowSplashScreen = strTemp
Else
    pbolShowSplashScreen = True
End If

strSection = "ErrorLog"
pstrErrProvider = UCase(objINI.strGetFromIni(strSection, "Provider", pstrConfigIniPath))
pstrErrDBPath = UCase(objINI.strGetFromIni(strSection, "Path", pstrConfigIniPath))
pstrErrEmail = UCase(objINI.strGetFromIni(strSection, "Email", pstrConfigIniPath))

MsgBox "ErrorLog read from ini file"

strSection = "Notes"
pstrNotesPath = UCase(objINI.strGetFromIni(strSection, "Path", pstrConfigIniPath))

MsgBox "Notes path from ini file"

'{{EA
ErrorHandler_Exit:
    Screen.MousePointer = 0
    Exit Sub
ErrorHandler:
    Call modErrorHandler.ErrorTrap(Err.Number, Err.Description, Err.Source, "GetDatabaseSettings", "modMain")
    GoTo ErrorHandler_Exit
'}}EA

End Sub


And this is the actual ini file:

; ====================================================
; THIS IS A STANDARD SECTION AND SHOULD BE FILLED OUT
; FOR EVERY PROGRAM BEING USED
; ====================================================

[Database]
Provider="{Pervasive ODBC Client Interface}"
ServerName="Balgord-14"
DatabaseName="BCODAT"

[ACCPAC_Database]
Provider="{Pervasive ODBC Client Interface}"
ServerName="Balgord-14"
DatabaseName="BCOQ"

[ACCPAC]
Version="54A"
APPID="GL"
ProgramName="GL0001"

[Project]
Title= [G/L Accounts]

[Preference]
ShowSplashScreen=false

[ErrorLog]
Provider=Microsoft.Jet.OLEDB.4.0
Path=C:\Program Files\Balgord\Database\ErrorLog.mdb
Email=test@test1.com

[Notes]
Path="\\Sbs-server\company\Projects\Notes.exe"

; ==================================================
; THIS IS A CUSTOM SECTION WHICH WILL CHANGE DEPENDING
; ON THE PROGRAM
; ==================================================

I'm pretty sure this is all
 
Thank you for your reply, I have fixed the issue, the stsTools.dll needed to be re-registered.

Thanks.
 
Another question regarding INI:

My GL Accounts application has a button which loads the NOtes.exe applicatoin using the INI file.

The problem is, the user can click on the button and it will open the Notes.exe applicaton when ever they click on this button.

So say they click the button 3 times the application will open 3 times.

Is there any sort of code i could put in the INI file or the program to detect if the Notes.exe application is opened or closed.

Any help will be much appreaciated.

Thank you.
 
Can you not just disable the button after it's been clicked?

Private Sub Command1_Click()
Command1.Enabled = False

'Your Open Notes.exe routine here

End Sub

[gray]Experience is something you don't get until just after you need it.[/gray]
 
Hi, thanks for the reply.

Yes but then when I close the Notes.exe application the GLAccounts.exe application doesnt recognize that its closed and the user is unable to click on the button.

I need to trigger it so that when the Notes.exe application is opened disable the button, and when the Notes.exe application is closed enable the button.

Thanks.

 
Try this.


This code is in the declarations:
Code:
' You can define the various SECURITY_ATTRIBUTES or use 0.
Public Type STARTUPINFO
        cb As Long
        lpReserved As Long
        lpDesktop As Long
        lpTitle As Long
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Long
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
End Type

Public Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
End Type

Public Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Boolean
End Type

Public lpStartUp As STARTUPINFO
Public lpProcess As PROCESS_INFORMATION
Public saProcessSecurity As SECURITY_ATTRIBUTES
Public saThreadSecurity As SECURITY_ATTRIBUTES
Public lProcessSuccess As Long

Public Declare CreateProcess Lib "kernel32" Alias "CreateProcessA" _
                       (ByVal lpApplicationName As String, _
                        ByVal lpCommandLine As String, _
                        ByRef lpProcessAttributes As SECURITY_ATTRIBUTES, _
                        ByRef lpThreadAttributes As SECURITY_ATTRIBUTES, _
                        ByVal bInheritHandles As Long, _
                        ByVal dwCreationFlags As Long, _
                        ByRef lpEnvironment As Any, _
                        ByRef lpCurrentDirectory As String, _
                        ByRef lpStartupInfo As STARTUPINFO, _
                        ByRef lpProcessInformation As PROCESS_INFORMATION) As Long

Public Declare Function GetExitCodeProcess Lib "kernel32" _
                       (ByVal hProcess As Long, _
	                    ByRef lpExitCode As Long) As Long

Then in the click event:
Code:
      lProcessSuccess = CreateProcess("C:\Lotus\Notes\nlnotes.exe", vbNullString, saProcessSecurity, _
                 saThreadSecurity, True, HIGH_PRIORITY_CLASS, vbNullString, _
                 vbNullString, lpStartUp, lpProcess)

       If (lProcessSuccess <> 0) then
          ' Disable your button.
          ' Set Timer interval and Enable timer here.
       Else
          ' Error code here.  Notes did not open.
       End if

Then place this code in your timer. The timer interval is whatever you are comfortable with.

Code:
        RetVal = GetExitCodeProcess(lpProcess.hProcess, lExitCode)

        If (lExitCode <> STILL_ACTIVE) then
           ' Enable button here
        End if

A lot of cut and paste. Hope I got it all. Let me know if you need more info.



HyperEngineer
If it ain't broke, it probably needs improvement.
 
Hyper,

with respect, I expect;

Your HIGH_PRIORITY_CLASS and lExitCode are undefined.

and

'Public Declare CreateProcess' should read 'Public Declare CreateProcess'
 
Thanks, this looks very similar to my code so i dont have to copy too much, the only thing i think thats missing is the declaration for lpExitCode.

Would i declare it as?

Thanks a bunch, I think this might work.
 
Heres my code

Option Explicit
Public lpProcess As PROCESS_INFORMATION

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadId As Long
End Type

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Declare Function CreateProcess Lib "kernel32" _
Alias "CreateProcessA" _
(ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
lpProcessAttributes As Any, _
lpThreadAttributes As Any, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
lpEnvironment As Any, _
ByVal lpCurrentDriectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function OpenProcess Lib "kernel32.dll" _
(ByVal dwAccess As Long, _
ByVal fInherit As Integer, _
ByVal hObject As Long) As Long

Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long

Public Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByRef lpExitCode As Long) As Long

Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&

Const MAXIMIZE_WINDOW = 3


Public Sub LaunchApp(vstrAppPath As String)
Dim pInfo As PROCESS_INFORMATION
Dim sInfo As STARTUPINFO
Dim sNull As String
Dim lSuccess As Long
Dim lRetValue As Long

sInfo.cb = Len(sInfo)
lSuccess = CreateProcess(sNull, vstrAppPath, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)

If lSuccess <> 0 Then
frmMain.cmdNotes.Enabled = False
frmMain.Timer1.Interval = 1000 And frmMain.Timer1.Enabled = True
Else

End If

'Dim wshShell As Object
'
'Set wshShell = CreateObject("WScript.Shell")
'wshShell.Run vstrAppPath, MAXIMIZE_WINDOW

End Sub




 
Irenavassilia,

You can declare it in the timer control.

Code:
Dim lpExitCode as long

STILL_ACTIVE and HIGH_PRIORITY_CLASS can be in the declaration section before the Public Declare statements:

Code:
Public Const STILL_ACTIVE as Long = &H103
Public Const HIGH_PRIORITY_CLASS as Long = &H80

Hope it works.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
Thanks alot hyper! it works... although it still pops up after 1000 miliseconds.
Is there any way that i could have it not pop up until the application is closed?

Thanks.

Regards,

Irena
 
Irena,

What does the code for the timer look like? What exactly is popping up?

Also, why are you anding the timer properties? Look at this:
Code:
If (Success <> 0) then
    frmMain.cmdNotes.Enabled = False
    frmMain.Timer1.Interval = 1000
    frmMain.Timer1.Enable = True
End If



HyperEngineer
If it ain't broke, it probably needs improvement.
 
Hyper,

I have it running with;

lSuccess = CreateProcess(sNull, vstrAppPath, ByVal 0&, ByVal 0&, 1&, HIGH_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, lpProcess)

rather than;

lSuccess = CreateProcess(sNull, vstrAppPath, ByVal 0&, ByVal 0&, 1&, NORMAL_PRIORITY_CLASS, ByVal 0&, sNull, sInfo, pInfo)
 
Hugh,

Irena made the same changes. The lpProcess was what I defined in my case. Irena changed it to pInfo. But I didn't think the HIGH_PRIORITY_CLASS would have made that kind of difference. I'm not sure what is popping up. Just maybe the NORMAL_PRIORITY_CLASS would fix it. Maybe. The HIGH_PRIORITY_CLASS would give notes most of the CPU time if it was required. That may be a good point depending on what Irena's application is doing while notes is running.



HyperEngineer
If it ain't broke, it probably needs improvement.
 
Hyper and Irena, apologies my last post should have been addressed to Irena. HIGH vs NORMAL_PRIORITY_CLASS does'nt seem to make much difference it was the LpProcess vs pInfo which did it.
 
Hi Hyper and Hugh, thanks for all your suggestions. Whats popping up is my Notes.exe application when I click on the cmdNotes button while Notes.exe is already opened, so say I push the button 5 times the Notes.exe application will pop up 5 times.
If I had frmNotes.exe in the main project this wouldnt be an issue but I dont have an option to do this.

With the timer, that I've created the only difference is that it doesnt pop up for a specific amount of time but it still pops up eventually.

I'm going to read everything you guys wrote here carefully one more time, with hopes of getting this to work.

Thanks alot Hugh and Hyper! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top