2012年5月8日 星期二
有關於單一執行個體 (不允許重覆執行)
在Form load裡面
Dim intTimes As Integer
Dim strMeName() As String
Dim strName As String
intTimes = 0
'取出名字,包涵檔名路徑
strMeName = Split(Application.ExecutablePath, "\")
'真正的名字是在最後一個
strName = strMeName(strMeName.Length - 1).ToUpper
'不要.exe結尾
strName = Split(strName, ".EXE")(0)
'偵測有無執行過了
For Each p As Process In Process.GetProcesses()
Try
For Each m As ProcessModule In p.Modules
If Mid(m.ModuleName, 1, strName.Length).ToUpper = strName Then
intTimes = intTimes + 1
End If
Next
Catch ex As Exception
End Try
Next
Try
'如果有兩個人,就離開
If intTimes > 1 Then
'自殺
'離開並關閉執行緒
Environment.Exit(Environment.ExitCode)
Application.Exit()
End If
Catch ex As Exception
End Try
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言