如何让自个编的程序不能同时开两个??

解决方案 »

  1.   

    sub Main ()    
        If App.PrevInstance Then
            End
        Else
            frmMain.Show
        End If
    end sub
      

  2.   

    Sub Main()    '检测是否已运行
        If App.PrevInstance Then
            MsgBox App.Title + " 已运行!"
            End
        End If
        ……
      

  3.   

    7.只容许运行一个程序实例(利用互斥体)选择启动对象为sub main()
    module:
    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()
        Dim sa As SECURITY_ATTRIBUTES
        sa.bInheritHandle = 1
        sa.lpSecurityDescriptor = 0
        sa.nLength = Len(sa)
        Debug.Print CreateMutex(sa, 1, App.Title)  '这一行可千万不能删除啊
        Debug.Print Err.LastDllError
        If (Err.LastDllError = ERROR_ALREADY_EXISTS) Then
            MsgBox "More than one instance"
        Else
        Form1.Show
        End If
    End Sub
    我都写了,为什么不去看了,有浪费了10分,呵呵
    http://community.csdn.net/Expert/topic/3649/3649442.xml?temp=.5771601
      

  4.   

    If App.PrevInstance Then
            MsgBox "TestBug已经在运行中!"
            End
    End If