Results 1 to 6 of 6

Thread: How To Check If A program is working before opening it again

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    120

    Question

    i have a program that works as an nt task and i want to check if the program is working before nt starts it again
    shachar shaty

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    You mean if a program is running?

    You can check if the classname already exists by using FindWindow API call.

    If you need help, ask!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    120
    Before i Check this problem i have another problem
    maybe you know what is "error 67 too many files" in VB
    shachar shaty

  4. #4
    Lively Member rekcus's Avatar
    Join Date
    Jan 1999
    Location
    Kuala Lumpur
    Posts
    122
    Perhaps this would help you.

    Dump the code to your starting sub.
    Code:
      If App.PrevInstance Then
        MsgBox "Application already running", vbInformation
        End
      End If
    "Error 67 too many files" should mean that you have
    too many files opened.
    penyou!

    "The code bytes.."

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    reckus, that doesn't good enough. You should use the FindWindow as Jop mention. "coz you need to restore the running application to be active window.

    Here juz a sample code. Assume your main form is call Form1 with caption set to Form1 as well.

    Code:
    Option Explicit
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private xhwnd As Long
    
    Public Sub Main()
    Dim xAppName As String
    If App.PrevInstance Then
        xAppName = "Form1"
        xhwnd = FindWindow(0&, xAppName)
        If xhwnd <> 0 Then
            AppActivate xAppName
            xhwnd = ShowWindow(xhwnd, SW_SHOWNORMAL)
            End
        End If
    End If
    
    Load Form1
    Form1.Show
    End Sub

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2000
    Posts
    120
    thank you all
    shachar shaty

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