在VB.net 下如何判断已经有一个程序的实例在运行》??
解决方案 »
- DLL已注册 还是错误“类不支持自动化
- 求sql语句,如何多条件求和?
- 用VBS怎么实现运行 intl.cpl 这个windows命令?批处理/C# 能实现也行.
- 那位答题猜迷高人能帮我把这个游戏填空完成?回复有分
- 简单问题!关于flash控件和日历控件(详细内容见贴)
- 有适合VB初学者看的书么?
- 请问如何将webBrowser控件中的页面打印出来?
- 欢迎讨论Visual Basic程序设计规范
- 在线求救,大神帮忙看下原因,同一编辑内容为什么现在更新就不一样了
- 关于调用C做的动态库的函数出参问题
- 高手们请进,编写tcp/ip通讯控件.dll用asp调用问题,高分求教?(银行系统)
- 哪位知道可以反编译用vb6编译的程序?
MsgBox("程序正在运行, 请检查窗口是否被最小化。", 48, "系统工具箱")
End If
Public Shared Function RunningInstance() As Process
Dim current As Process = Process.GetCurrentProcess()
Dim processes As Process() = Process.GetProcessesByName(current.ProcessName)
'Loop through the running processes in with the same name
Dim process As Process
For Each process In processes
'Ignore the current process
If process.Id <> current.Id Then
'Make sure that the process is running from the exe file.
If [Assembly].GetExecutingAssembly().Location.Replace("/", "\") = current.MainModule.FileName Then
'Return the other process instance.
Return process
End If
End If
Next process
'No other instance was found, return null.
Return Nothing
End Function 'RunningInstance
Private Function IsInstanceRunning() As Boolean
Dim current As Process = System.Diagnostics.Process.GetCurrentProcess()
Dim processes As Process() = System.Diagnostics.Process.GetProcessesByName(current.ProcessName)
Dim p As Process
For Each p In processes
If p.Id <> current.Id Then
If System.Reflection.Assembly.GetExecutingAssembly().Location.Replace("/", "\") = current.MainModule.FileName Then
Return True
End
End If
End If
Next
Return False
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As Boolean
a = IsInstanceRunning()
If a = True Then
MsgBox("程序已经运行", , "系统")
Else
End If
End Sub