CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2001
    Location
    Singapore.
    Posts
    7

    Application Status

    Hi Gurus,

    How can I check that my one of my aplication's instance is already running ?

    Thanks,
    Krogoth!

    FSM

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Application Status


    '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
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Dec 2001
    Location
    Belgium
    Posts
    4

    Re: Application Status

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured