就是怎么判断一个应用程序已经打开,不允许再次打开的时候
请指教,谢谢 急
10 个解决方案
#1
好象是不行的,支持并行是DONET的特色噢!(我只是随便说说,我也不清楚,呵呵~~~)
#2
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=F7810234-04D8-4F9C-B1C7-925919E691FF
摘录自孟子E章:
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
摘录自孟子E章:
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
#3
Dim mProcs() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
Dim sProc As System.Diagnostics.Process
For Each sProc In mProcs
If sProc.ProcessName = "yourapp.exe" Then
MsgBox("有一个程序已经运行!")
End If
Next
Dim sProc As System.Diagnostics.Process
For Each sProc In mProcs
If sProc.ProcessName = "yourapp.exe" Then
MsgBox("有一个程序已经运行!")
End If
Next
#4
楼上,好像"yourapp.exe",应该是"yourapp",不应该有".exe"吧
#5
怎样才能使当前的程序退出,原来的程序激活(active)?
#6
Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As IntPtr) As Integer
Public Sub Main(ByVal args() As String)
Dim instance As Process = RunningInstance()
If Not (instance Is Nothing) Then
MsgBox("此程序已經在運行!", MsgBoxStyle.Information, "提示信息")
SetForegroundWindow(instance.MainWindowHandle)
End
End If
end sub
Public Sub Main(ByVal args() As String)
Dim instance As Process = RunningInstance()
If Not (instance Is Nothing) Then
MsgBox("此程序已經在運行!", MsgBoxStyle.Information, "提示信息")
SetForegroundWindow(instance.MainWindowHandle)
End
End If
end sub
#7
在你的if语句中加一个end或者application.exit不就退出了吗?
#8
谢谢 landlordh(software), 问题解决了。
#9
EricBai(Eric), 我是说不但要退出,还要把原来的程序激活,只能用api了
#10
??
你的问题不是说 “就是怎么判断一个应用程序已经打开,不允许再次打开的时候”吗?
如果你第二次运行它就会自动退出阿?我不太明白为什么要激活先前正在运行的程序阿?它不是正在运行中吗?
你的问题不是说 “就是怎么判断一个应用程序已经打开,不允许再次打开的时候”吗?
如果你第二次运行它就会自动退出阿?我不太明白为什么要激活先前正在运行的程序阿?它不是正在运行中吗?
#1
好象是不行的,支持并行是DONET的特色噢!(我只是随便说说,我也不清楚,呵呵~~~)
#2
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=F7810234-04D8-4F9C-B1C7-925919E691FF
摘录自孟子E章:
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
摘录自孟子E章:
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
#3
Dim mProcs() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcesses
Dim sProc As System.Diagnostics.Process
For Each sProc In mProcs
If sProc.ProcessName = "yourapp.exe" Then
MsgBox("有一个程序已经运行!")
End If
Next
Dim sProc As System.Diagnostics.Process
For Each sProc In mProcs
If sProc.ProcessName = "yourapp.exe" Then
MsgBox("有一个程序已经运行!")
End If
Next
#4
楼上,好像"yourapp.exe",应该是"yourapp",不应该有".exe"吧
#5
怎样才能使当前的程序退出,原来的程序激活(active)?
#6
Public Declare Function SetForegroundWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As IntPtr) As Integer
Public Sub Main(ByVal args() As String)
Dim instance As Process = RunningInstance()
If Not (instance Is Nothing) Then
MsgBox("此程序已經在運行!", MsgBoxStyle.Information, "提示信息")
SetForegroundWindow(instance.MainWindowHandle)
End
End If
end sub
Public Sub Main(ByVal args() As String)
Dim instance As Process = RunningInstance()
If Not (instance Is Nothing) Then
MsgBox("此程序已經在運行!", MsgBoxStyle.Information, "提示信息")
SetForegroundWindow(instance.MainWindowHandle)
End
End If
end sub
#7
在你的if语句中加一个end或者application.exit不就退出了吗?
#8
谢谢 landlordh(software), 问题解决了。
#9
EricBai(Eric), 我是说不但要退出,还要把原来的程序激活,只能用api了
#10
??
你的问题不是说 “就是怎么判断一个应用程序已经打开,不允许再次打开的时候”吗?
如果你第二次运行它就会自动退出阿?我不太明白为什么要激活先前正在运行的程序阿?它不是正在运行中吗?
你的问题不是说 “就是怎么判断一个应用程序已经打开,不允许再次打开的时候”吗?
如果你第二次运行它就会自动退出阿?我不太明白为什么要激活先前正在运行的程序阿?它不是正在运行中吗?