就是每次只能运行一个应用程序,我忘记怎么做了
谢谢!

解决方案 »

  1.   

    Private Sub Form_Load()
    If App.PrevInstance Then
        MsgBox App.EXEName & 已经启动了"
        End
    End If
    End Sub
      

  2.   

    同意楼上,不过应尽量避免用end强行退出。
      

  3.   

    不用end强行退出,那应该怎么办?
      

  4.   

    else
       .........
    根据你自己的需要来做啊。
      

  5.   

    还是利用互斥体比较好
    模块中
    Public Declare Function CreateMutex Lib "kernel32" Alias "CreateMutexA" (lpMutexAttributes As SECURITY_ATTRIBUTES, ByVal bInitialOwner As Long, ByVal lpName As String) As Long
    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
    当然要把启动窗体改为sub main()
      

  6.   

    互斥比较麻烦,tztz520闲兄的较好
      

  7.   

    那还是不样的,tztz520的方法在以下几中情况下是不起作用的 
    1  更改可执行文件名
    2  更改可执行文件路径等
    而利用互斥体则不存在这种问题。