none
Check for open winform app RRS feed

  • Question

  • Hi

    Is there a way to check from one app if another winform app is already running by checking the app's main (and only) form's caption (text)? 

    Thanks

    Regards

    Tuesday, October 9, 2018 2:45 AM

Answers

  • Hi,

    Find the window handle name to determine if a program is open

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("User32.dll", EntryPoint:="FindWindow")>
        Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        End Function
    
    
    
        Dim hwWnd As IntPtr = New IntPtr(0)
        Public Shared Function WindowFind(ByVal WindowName As String) As IntPtr
            Dim ParenthWnd As IntPtr = New IntPtr(0)
            ParenthWnd = FindWindow(Nothing, WindowName)
            Return ParenthWnd
        End Function
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            hwWnd = WindowFind("windowsname")
            If hwWnd <> 0 Then
                MsgBox("OK")
            End If
    
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Y a h y a Friday, October 12, 2018 7:33 AM
    Tuesday, October 9, 2018 5:03 AM
  • If you know the name of the second application (file name without extension), then try this:

    Dim already_running = Process.GetProcessesByName("some name").Any

    If you only know the caption, then:

    Dim already_running = Process.GetProcesses.Any(Function(p) p.MainWindowTitle = "some caption")


    • Marked as answer by Y a h y a Friday, October 12, 2018 7:33 AM
    Tuesday, October 9, 2018 5:06 AM

All replies

  • Hi,

    Find the window handle name to determine if a program is open

    Imports System.Runtime.InteropServices
    
    Public Class Form1
        <DllImport("User32.dll", EntryPoint:="FindWindow")>
        Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
        End Function
    
    
    
        Dim hwWnd As IntPtr = New IntPtr(0)
        Public Shared Function WindowFind(ByVal WindowName As String) As IntPtr
            Dim ParenthWnd As IntPtr = New IntPtr(0)
            ParenthWnd = FindWindow(Nothing, WindowName)
            Return ParenthWnd
        End Function
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            hwWnd = WindowFind("windowsname")
            If hwWnd <> 0 Then
                MsgBox("OK")
            End If
    
        End Sub
    End Class

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Y a h y a Friday, October 12, 2018 7:33 AM
    Tuesday, October 9, 2018 5:03 AM
  • If you know the name of the second application (file name without extension), then try this:

    Dim already_running = Process.GetProcessesByName("some name").Any

    If you only know the caption, then:

    Dim already_running = Process.GetProcesses.Any(Function(p) p.MainWindowTitle = "some caption")


    • Marked as answer by Y a h y a Friday, October 12, 2018 7:33 AM
    Tuesday, October 9, 2018 5:06 AM