Results 1 to 3 of 3

Thread: Another Program Running?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 1999
    Location
    Ireland
    Posts
    96

    Post

    How do I find out if another program is running from within my program. IE. Is excel currently active and if not then I'll start it.

    I know how to start Excel etc... but how do I detect if it is already running.

    Thanks in advance,
    Steve.



  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I just can't remeber what classname you have to pass but you could find out. Anyway if you know the classname you can use findwindow that will return the handle if there is at least one instance of excel running. otherways it will return 0
    Code:
    'in declarations
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    'in code
    wnd = FindWindow(classname,vbnullstring)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Guest
    Try this:

    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    
    Private Sub Command1_Click()
    
        Retval = FindWindow("XLMAIN", 0&)
        If Retval = 0 Then
            MsgBox ("Excel is not running")
        Else
            MsgBox ("Excel is running")
        End If
    
    End Sub

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