Public Function IsInstanceRunning() As Boolean
Dim current As Process = System.Diagnostics.Process.GetCurrentProcess()
Dim processes As Process() = System.Diagnostics.Process.GetProcessesByName(current.ProcessName)
'Loop through the running processes in with the same name
Dim p As Process
For Each p In processes
'Ignore the current process
If p.Id <> current.Id Then
'Make sure that the process is running from the exe file.
If System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", "/") = current.MainModule.FileName Then
'Return the other process instance.
Return True
End If
End If
Next
'No other instance was found, return null.
Return False
End Function 'RunningInstance
限制同一台机器上只能运行一个实体(.NET中VB语言)
最新推荐文章于 2024-07-23 23:25:30 发布