Community discussion forum

Check to see if Application is still running

  • 2 years ago

    Ok so I was having trouble e-mailing from vb 6.0 so I wrote an exe in vb.net and I call it from my VB 6.0 program.  What I want to do is wait until my .net program has finished and closed before I move on to the next step in my vb 6 application.  Is there a way to check to see if the program which is called PrintMonthends.exe is still running or not. Please help

     

    Thanks in advance,

    Chris.

  • 2 years ago

    Some solutions come to my mind, but there may be a lot more... Wink 

    1. If you have a folder that can be accessed by both programs tell the VB.Net application to write a small file when it has finished (e.g. ready.txt). From within your VB6 application check for this file every x seconds.

    2. Use some API calls to exchange messages between both applications.

    3. Rewrite the VB6 part with VB.Net.

  • 2 years ago
    hi i found following code on developerFusion and i have added isProcessRunning function it it. call following function to test whether exe is running or not Private Function IsProcessRunning(ProcessName As String) As Boolean Dim hSnapShot As Long, uProcess As PROCESSENTRY32 Dim r As Long Dim rstA As New ADODB.Recordset rstA.Fields.Append "process", adBSTR rstA.Open hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&) uProcess.dwSize = Len(uProcess) r = Process32First(hSnapShot, uProcess) Do While r rstA.AddNew rstA.Fields(0).Value = Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0)) r = Process32Next(hSnapShot, uProcess) Loop CloseHandle hSnapShot If rstA.RecordCount > 0 Then rstA.MoveFirst rstA.Find "process = '" & ProcessName & "'" IsProcessRunning = Not rstA.EOF Else IsProcessRunning = False End If End Function ************************ paste following code in a module Option Explicit 'Constants Public Const TH32CS_SNAPHEAPLIST = &H1 Public Const TH32CS_SNAPPROCESS = &H2 Public Const TH32CS_SNAPTHREAD = &H4 Public Const TH32CS_SNAPMODULE = &H8 Public Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE) Public Const TH32CS_INHERIT = &H80000000 Public Const MAX_PATH As Integer = 260 'Type Public Type PROCESSENTRY32 dwSize As Long cntUsage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long dwFlags As Long szExeFile As String * MAX_PATH End Type 'API Declaration Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long Public Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long regards manpreet singh dhillon hoshiarpur
  • 2 years ago

    Hey m9815402440 can you post the link to that page so I can see it broken out.

    Thanks

  • 2 years ago

    I know how to create a folder in vb.net but how do I check to see if it exists in vb 6?  If so how would I the loop to check the folder every X seconds in vb 6? 

  • 1 year ago

    Please have a look at this code:

    Option Explicit
    
    Dim File As String
    Dim FileContent As String
    
    Private Sub Check_VBNET_App()
    FileContent = ""
    File = "c:\test.txt"
    Open File For Input As #2
    Input #2, FileContent
    If FileContent = "1" Then
        MsgBox "VB.Net application has terminated."
    Else
        MsgBox "VB.Net application is still running."
    End If
    Close #2
    
    End Sub
    
    Private Sub Form_Load()
    Timer1.Interval = 15000
    End Sub
    
    Private Sub Timer1_Timer()
    Check_VBNET_App
    End Sub


    I'm using a small text file. "1" indicates that your VB.Net app has finished it's work, all other text indicates that your VB.Net app is still running. With the above code, your VB6 app checks every 15 seconds if your VB.Net app is still running.

    A possible scenario would be:

    - Start your VB6 app, but dont start the timer.

    - Do something.

    - Write "99" to the small text file, start the timer, call your vb.net app.

    - vb.net app is doing something. When it has finished it's job, it writes "1" to the small text file. Vb.Net app terminates itself.

    - vb6 app stops the timer and procedes.

  • 1 year ago

    Hi,

    I think you are calling Visual Basic .NET exe file using Shell function in VB 6.0, when you call the shell function it will return you the handle number of that application. So with that hwnd or handle number you have the provision to check whether handle is still running or not. You try to get a function from API, If you wont get it contact me I will let you know the API call.

    sambariramesh@gmail.com 

    Ramesh Sambari

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback