Hi Gurus,
How can I check that my one of my aplication's instance is already running ?
Thanks,
Krogoth!
FSM
Printable View
Hi Gurus,
How can I check that my one of my aplication's instance is already running ?
Thanks,
Krogoth!
FSM
'Two ways:
'the easiest (but not always working for sure, as it search only in your
'program's working directory) is app.previnstance
'ie:
if app.previnstance then
unload me
end if
'the other is using Api and works fine as long as your programs display forms.
'Here is a ling to the code of Iouri who showed how to do it:
http://codeguru.com/cgi-bin/bbs/wt/s...=63050&Search=true&Forum=vb&Words=Check&Match=Whole&Topic=&Searchpage=1&Limit=25
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
Hi,
If you start your application with a shell function then you can determine the status of your application with the following code:
private Declare Function WaitForSingleObject Lib "kernel32" (byval _
hHandle as Long, byval dwMilliseconds as Long) as Long
private Declare Function CreateProcessA Lib "kernel32" (byval _
lpApplicationName as string, byval lpCommandLine as string, byval _
lpProcessAttributes as Long, byval lpThreadAttributes as Long, _
byval bInheritHandles as Long, byval dwCreationFlags as Long, _
byval lpEnvironment as Long, byval lpCurrentDirectory as string, _
lpStartupInfo as STARTUPINFO, lpProcessInformation as _
PROCESS_INFORMATION) as Long
private Declare Function CloseHandle Lib "kernel32" _
(byval hObject as Long) as Long
private Declare Function GetExitCodeProcess Lib "kernel32" _
(byval hProcess as Long, lpExitCode as Long) as Long
public Function ExecCmd(cmdline$)
Dim proc as PROCESS_INFORMATION
Dim start as STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = len(start)
' Start the shelled application:
ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret&
End Function
Good luck!
SAE