VB防止程序重复运行
来源:百度知道 编辑:UC知道 时间:2024/05/26 11:42:24
最佳答案,无论放到哪个盘符下,都可以检测出来是否开启!
Private Function Enum1() As String
Dim WMI
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_Process")
For Each obj In objs
Enum1 = Enum1 + obj.Description + Chr(13) + Chr(10)
Next
End Function
Private Sub Form_Load()
Dim Progress As Variant
Dim i As Integer
Static num As Integer
Progress = Split(Enum1, vbCrLf)
For i = 1 To UBound(Progress) - 1
If Progress(i) = "1.exe" Then '这里的"1.exe"改成你制成exe文件的名称
num = num + 1
If num > 1 Then
MsgBox "程序已经开启!"
End
End If
End If
Next
End Sub
Private Sub Form_Load()
If App.PrevInstance = True Then End
End Sub
加个这个就ok了
自己调用API进程函数去实现吧。请把你的分数攥牢,谁都不要给!