VBで重複起動防止処理のサンプル

クライアントプログラムをコマンドラインパラメータでシステムを切り変えるシステムの
重複起動防止処理のサンプル。


例)
1モジュールで2システムが動作し、それぞれのモジュールは1プロセスのみの起動とする。
それぞれのプログラムは「MainWindowTitle」で区別できる前提とする。

        Dim localProcAll As Process() = Process.GetProcesses()
        'Dim ActiveVal As Integer
        Dim checkWord As String
        If Microsoft.VisualBasic.Command = "msj" Then
            checkWord = "Aシステム"
        Else
            checkWord = "Bシステム"
        End If
        Dim p As Process
        For Each p In localProcAll
            '取得したプロセスの プロセスID・プロセス名・ウィンドウのキャプション名を表示
            'Console.WriteLine("{0} / {1} : {2}", p.Id, p.ProcessName, p.MainWindowTitle)
            If p.ProcessName = "プロセス名" Then
                If p.MainWindowTitle = checkWord Then
                    MsgBox(checkWord + "は既に起動しています。")
                    End
                End If
            End If
        Next

Bookmark this on Yahoo Bookmark
Bookmark this on Google Bookmarks
Share on LinkedIn
LINEで送る
Pocket