近段时间,需要写一个小功能,就是需要判断程序是否已经运行。
某个程序安装后,也许被多个用户运行。那怎样判断当前用户已经运行了此程序了呢?

下面是Insus.NET的做法,就是:


源代码:

 Public Shared Function IsRunning(processName As String) As Boolean
            Dim btnIsRun As Boolean = False

            Dim owner As String = GetProcessOwner(App)
            Dim po As String = owner.Substring(owner.LastIndexOf("\") + 1)

            Try
                Dim listProc() As System.Diagnostics.Process
                listProc = System.Diagnostics.Process.GetProcessesByName(processName)
                If listProc.Length > 0 AndAlso GetUserName() = po Then
                    btnIsRun = True
                Else
                    btnIsRun = False
                End If
            Catch ex As Exception
                btnIsRun = False
            End Try
            Return btnIsRun
        End Function
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-01
  • 2022-02-02
  • 2021-11-28
相关资源
相似解决方案