프로세스 중복실행 방지 팁

VNote 2017.07.23 09:28:36 *: 프로세스 중복실행 방지 팁

Public Class Form1

    Private P As Process
    Private app As String = "notepad"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        P = Process.Start(app)
    End Sub


    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        For Each proc As Process In Process.GetProcessesByName(app)
            If proc.Id <> P.Id Then
                proc.CloseMainWindow()
            End If
        Next
    End Sub
End Class