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,
 
I think this might help: you can use OpenProcess with the PROCESS_QUERY_INFORMATION flag to determine if a given handle represents an open process. Do a search in this forum for IsProcessRunning for some examples.

So, store the handle for notes.exe when you open it, and every time the user pushes the button check if the process is already open. Or, use a timer to periodically check for your stored handle, and do your enable/disable routine based on the results.

HTH

Bob
 
Irena,

The problem is that Notes opens up fine, but then Notes must start another thread. This renders the original process handle inactive and the lpExitCode goes to zero. So it's a two fold process to see if Notes is still open. Initially, you have to check the lpExitCode. Then use FindWindow to see it the main Lotus Notes form closes. Here is my code. All of it is in the form (.frm file). I did not use any modules (.bas files).

Code:
Option Explicit

Const SYNCHRONIZE = 1048576
Const NORMAL_PRIORITY_CLASS = &H20&
Const STILL_ACTIVE As Long = &H103&
Const HIGH_PRIORITY_CLASS As Long = &H80&
Const MAXIMIZE_WINDOW = 3

Private pInfo 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

Private Declare Function GetExitCodeProcess Lib "kernel32" _
                       (ByVal hProcess As Long, _
                        ByRef lpExitCode As Long) As Long
                        
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
                       (ByVal lpClassName As String, _
                        ByVal lpWindowName As String) As Long



Private Sub cmdNotes_Click()
   
   Dim sAppPath As String
   
   sAppPath = "c:\lotus\notes\notes.exe"
'   sAppPath = "c:\winnt\notepad.exe"
   
   Call LaunchApp(sAppPath)
   
End Sub


Private Sub cmdQuit_Click()
   
   Unload Me
   
End Sub


Private Sub Timer1_Timer()
   
   Dim lpExitCode As Long, lHandle As Long
   Dim RetVal As Long
   
   RetVal = GetExitCodeProcess(pInfo.hProcess, lpExitCode)
   
   Debug.Print lpExitCode
   
   If (lpExitCode <> STILL_ACTIVE) Then
      
      ' If the lpExitCode goes to 0 then check for window
      lHandle = FindWindow(vbNullString, "Workspace - Lotus Notes")
      
      If (lHandle = 0) Then
         
         ' Window not found
         ' Enable button here
         cmdNotes.Enabled = True
         
         'Disable timer
         Timer1.Enabled = False
         
      End If
      
   End If
   
End Sub


Public Sub LaunchApp(vstrAppPath As String)
   
'   Dim pInfo As PROCESS_INFORMATION
   Dim sInfo As STARTUPINFO
   Dim sNull As String
   Dim lSuccess As Long, lNotesHandle As Long
   
   sInfo.cb = Len(sInfo)
   lSuccess = CreateProcess(vstrAppPath, _
                            "c:\notes", _
                            ByVal 0&, _
                            ByVal 0&, _
                            1&, _
                            NORMAL_PRIORITY_CLASS, _
                            ByVal 0&, _
                            vbNullString, _
                            sInfo, _
                            pInfo)
   lNotesHandle = pInfo.hProcess
   
   If lSuccess <> 0 Then
      
      frmMain.cmdNotes.Enabled = False
      frmMain.Timer1.Interval = 1000
      frmMain.Timer1.Enabled = True
      
   Else
      
      Call MsgBox("Notes did not start", vbOKOnly, "Notes")
      
   End If
   
End Sub

The button will not be enabled until you exit notes. So you will only be able to have one instance of Notes.

Let me know how this works. It worked on my machine.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
> Notes opens up fine, but then Notes must start another thread.

Hyper, I was thinking that notes started in another process rather than another thread. Is that not correct?
 
Bob,

This is true. VB opens up Notes in another process, but Notes itself appears to open up the main program in another thread (or process) after the splash screen closes. This is evident because the exit code changes from STILL_ACTIVE to 0. That's why I had to use FindWindow. Irena will have to open Notes and see what the window title is. It may be different depending on the version of Notes.



HyperEngineer
If it ain't broke, it probably needs improvement.
 
<in another thread (or process)

Which? Another thread or another process?

If it opens up in the same process, but on a different thread, you should be able to store the process handle and use it later to reference the process. So, maybe Notes is really creating two different processes, one for the splash screen and one for the app itself. However, it seems pretty strange to me. However again, Notes has always seemed pretty strange to me as well.

Bob
 

Notes must open up a new process. If it were a new thread, then you're right, the process handle should still be valid. Since the process handle goes to zero, then the intial process closes out. I believe, notes.exe calls nlnotes.exe. You can see that by opening the task manager and watching the processes. Notes.exe and nlnotes.exe start up then notes.exe closes and nlnotes.exe stays. After a short while ntaskldr.exe starts. When Notes is exited, nlnotes.exe and ntaskldr.exe close.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
Ok, I'm clear now. So now I'm curious what the inherit handle flag does; you have it set to 1h which I assume means true. I would think that it would allow you to use the handle you got in Createprocess to reference child processes that the initial process creates. Got any insight into that?
 
Bob,

Setting the inheritance to true means that the child process can inherit any open inheritable handles from the calling (parent) process. But I don't see anything for the reverse route. If I could reverse-inherit the handles, I'm not sure how I would know when they were created and opened.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Oh, I see. I was thinking that the child would take on the handle of the parent, but that of course doesn't make sense because you'd have the same handle for two different processes.
 
I'm curious to know whether the Notes that seems to be being talked about at this end of the thread (Lotus Notes) is the same as the Notes the OP described ("another VB application").
 
Looking back, it does seem that the VB application Notes is not the same as Lotus Notes. My oversight, again. The code should be fine without the FindWindow portion. Just look for the exit code and you are done. Thanks for the observation. I checked the original code, without the FindWindow function, and it worked fine with notepad. However, I don't know what the VB Notes application does. If it in itself does call another process, then Irena will have to use the FindWindow function. But Irena will have to substitute the window title of the VB Notes application.

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

Sorry I havent even had the chance to respond to your replies due to another critical situation at work which finally has been fixed.

I will try out Hypers code and let you know how it goes, thank you guys for all these posts!

Regards,

Irena
 
Hi Hyper,

A few question regarding the code:

Code:
lHandle = FindWindow(vbNullString, "Workspace - Lotus Notes")

Q: is this the name of the program? should mind be "BCOQ - GL Comments", i'm not really sure what name i would put in there.

Code:

lSuccess = CreateProcess(vstrAppPath, _
"c:\notes", _
ByVal 0&, _
ByVal 0&, _
1&, _
NORMAL_PRIORITY_CLASS, _
ByVal 0&, _
vbNullString, _
sInfo, _
pInfo)

Q: that doesnt work because of the "c:\notes", what is the difference between what i have for lSuccess and this code?

I think the reason its not working is because it cant find the window.. this code looks very good though, i'll work through it, hopefully figure it out soon.

Thanks a bunch!
 
>should mind be "BCOQ - GL Comments"

Well, that answers my question ...
 
>Well, that answers my question ...

Yea its not a Lotus program its a custom notes VB program that i made.

is that the answer you needed?
 
Irena,

If your VB application "BCOQ - GL Comments" does not start another process after a splash screen, then you won't need FindWindow(). However, if you do then the text in the title bar of the "BCOQ - GL Comments" application should be what FindWindow() is looking for. I used "Workspace - Lotus Notes" because that's what's in the title bar for Lotus Notes. Hope this clears it up.


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

I replaced the code with the window name of my application but it still doesnt find it.

lHandle = FindWindow(vbNullString, "BCOQ - G/L Comments")
 
Hi Hyper,

I changed the code a little bit and it works:

If (lHandle <> 0) Then

' Window found
cmdNotes.Enabled = False
ElseIf (lHandle = 0) Then
' Window closed
cmdNotes.Enabled = True
End If

Thanks alot for all your help guys :eek:)
 
Irena,

I'm glad it works, and thanks for the star.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top