各位高手们:我的意思是:
我有一个应用程序,工程名称为MyProj,我现在已经运行这个程序,不想让用户再次运行,当用户第二次运行时提示用户已经运行过此程序了!急!!请高手们提教!!!!!!谢谢!!
我有一个应用程序,工程名称为MyProj,我现在已经运行这个程序,不想让用户再次运行,当用户第二次运行时提示用户已经运行过此程序了!急!!请高手们提教!!!!!!谢谢!!
调试欢乐多
Public Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Public Const ERROR_ALREADY_EXISTS = 183&
Private Sub Main()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: [email protected]
' -> code by Raist Lin
Dim sa As SECURITY_ATTRIBUTES
sa.bInheritHandle = 1
sa.lpSecurityDescriptor = 0
sa.nLength = Len(sa)
'Try to create a new Mutex
Debug.Print CreateMutex(sa, 1, App.Title)
Debug.Print Err.LastDllError
'Check if the function was succesfull
If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
'More than one instance detected
MsgBox "More than one instance"
Else
Form1.Show
'No other instance detected...
'Your program-load code here
End If
End Sub
讨论过一千次了。
If App.PrevInstance Then
MsgBox App.Title + " 已运行!"
End
End If
打开EXE文件---》修改EXE文件名---》双击EXE文件,看到没,又一个窗口弹出来了。
或者
打开EXE文件---》拷贝EXE文件到另外一处---》双击移动后的EXE文件,看有什么结果
再用互斥体试试上面的操作,看有没有这个问题。
每次运行,先看看有没有这个记号咯。
你可以在注册表、文件、数据库、INI、.....等等N个角落里做。