如何防止程序多次运行

zymfy 2003-04-24 02:44:52
如何防止程序多次运行?
...全文
120 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Latitude 2003-04-24
  • 打赏
  • 举报
回复
在本版就有呀:
http://expert.csdn.net/Expert/topic/1645/1645639.xml?temp=.6115381
   Dim pProcess() As Process
pProcess = Process.GetProcesses()
Dim i As Integer
Dim count As Integer = 0
For i = 0 To pProcess.Length() - 1
'检查是否已经启动过
If (pProcess(i).ProcessName = "WindowsApplication1") Then
count += 1
End If
Next
If count > 1 Then
End '关闭要启动的这个程序
End If

---
by Henry
lx1920 2003-04-24
  • 打赏
  • 举报
回复
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
lx1920 2003-04-24
  • 打赏
  • 举报
回复
http://www.syncfusion.com/FAQ/WinForms/FAQ_c40c.asp#q550q
genny 2003-04-24
  • 打赏
  • 举报
回复
帮你顶

16,721

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧