Vb.Net防止同一程序重复运行的方法
2007-11-27 22:08
936 查看
防止同一个程序多次运行。
'*****************方法一:防止程序多次打开*****************
' 函数名: IsInstanceRunning
' 功 能: 判断工程是否已运行
' 参 数: 无
' 返回值: True 已运行 False 未运行
'*******************************************************
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
'*****************方法二:防止程序多次打开*****************
Imports System.Diagnostics
If UBound(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)) _
> 0 Then Eixt Sub
'Process.GetCurrentProcess.ProcessName 获取当前运行程序的名称。
'*****************方法一:防止程序多次打开*****************
' 函数名: IsInstanceRunning
' 功 能: 判断工程是否已运行
' 参 数: 无
' 返回值: True 已运行 False 未运行
'*******************************************************
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
'*****************方法二:防止程序多次打开*****************
Imports System.Diagnostics
If UBound(Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)) _
> 0 Then Eixt Sub
'Process.GetCurrentProcess.ProcessName 获取当前运行程序的名称。
相关文章推荐
- [WinForm]C# .net防止一个程序(WinForm)重复运行的方法。
- [WinForm]C# .net防止一个程序(WinForm)重复运行的方法。
- C# .net防止一个程序(WinForm)重复运行的方法。
- C# .net防止一个程序(WinForm)重复运行的方法。
- VB.NET程序运行耗时精确计量方法之一
- 防止同一个程序多次运行。 [VB.NET]
- 防止同一个程序多次运行。 [VB.NET]
- QT之防止程序重复运行方法
- [VB.NET源码]防止运行重载多个程序实例
- WinForm防止程序重复运行的方法分析
- [VB.NET]怎样才能在自己的程序自动运行后获得系统中被点击文件夹的路径?(下)
- Winform防止程序重复运行
- 防止重复运行程序并且激活当前正在运行的窗口
- 如何判断程序是否重复运行的几种方法
- 忆龙2009:windows mobile防止程序重复运行
- 在VS.net调试环境中运行网站程序时ReportViewer控件的工具栏显示为英文的解决方法
- 不安装.net framework框架运行.Net 程序的方法
- 如何判断程序是否重复运行的几种方法
- 如何防止窗体重复打开(程序或表单重复运行)?
- [VB] 防止程序运行多个实例