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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is an app already running?

Status
Not open for further replies.

svankley

MIS
Aug 25, 2000
45
US
What's the best way in VB6 to see if an external application is running? It's not the VB app (as in app.previnstance...), it's another apoplication that should be running but minimized in the background.

Thanks,

Steve
 
Depends... what application are you refering to...?

You could use the API functions...

Or simply:
Code:
Dim X as Object
On Error Resume Next
X = GetObject("[b][i]Application.Name[/i][/b]")
If X is Nothing
  'Application Not Running
Else
  'Application Is Running
End
On Error Goto 0

the API is a bit trickier...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
BTW...
X = GetObject("Application.Name")
will be:
X = GetObject(,"Application.Name")

After you know what the Application Name is...

And again, that's assuming you can use this method...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I'm checking to see if acrobat is already running. I have a working app that creates a new instance of a pdf in memory, but has fits if acrobat isn't already running. If acrobat is already running and minimized everyhting works fine.
 
Can you post your code...

I imagine you just need to add some error trapping...
similar to that shown above...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
I actually used this:

If FindWindow(vbNullString, "Adobe Acrobat Standard") = 0 Then ' means Acrobat not running
Shell "C:\Program Files\Adobe\Acrobat 6.0\Acrobat\Acrobat.exe", 6
Sleep 1000 ' Give it a sec to open
End If

Thanks for all your suggestions,

Steve
 
So, you got it working?

FindWindow was the API I was refering to... But it can be limiting when using it with Shell... And complicated otherwise...

I was going to suggest something similar to this:
Code:
Function pageCount(inputFile As String) As Integer
Dim pdfDoc As Object
  On Error Resume Next
    'Try to connect to an existing instance
    [b]Set pdfDoc = GetObject(,"AcroExch.PDDoc")[/b]
    'Test the connection
    If pdfDoc Is Nothing Then
      'If Not Found, Try to create a new instance
      [b]Set pdfDoc = CreateObject("AcroExch.PDDoc")[/b]
    End If
    If pdfDoc Is Nothing Then Exit Function
    'Try to Open the document
    If pdfDoc.Open(inputFile) = False Then
      'Return File Not Found Error
      MsgBox "FileNotFoundException"
      Exit Function
    End If
    ' Get the number of pages
    pageCount = pdfDoc.GetNumPages
  On Error Goto 0
End Function

Not sure about the "AcroExch.PDDoc" object, I pulled that off this site...
and modified it from some .NET code... (I don't have acrobat)

If it does work, a quick google search might get you some further interesting information...

Hope This Helps ;-)

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top