使用VB编辑的一个程序,如何再第二次运行该程序的时候提示,此程序已经运行!多谢了!

解决方案 »

  1.   

    If App.PrevInstance Then
        MsgBox "程序已经运行!", vbInformation
        End
    End If
      

  2.   

    Private Sub Form_Load()
        If App.PrevInstance = True Then
            MsgBox "系统已启动,请按ALT+TAB键查找"
            Unload Me
            Exit Sub
        End If
     
    End Sub
      

  3.   

    Option Explicit
    Public Sub CheckExist(fm As Form)
    Dim title As String
    If App.PrevInstance Then
       title = App.title
       Call MsgBox("这程序已执行", vbCritical)
       App.title = ""    '如此才不会Avtivate到自己
       fm.Caption = ""
       AppActivate title 'activate 先前就已行的程序
       End
    End If
    End SubPrivate Sub Form_Load()
    Call CheckExist(Me)
    End Sub
      

  4.   

    如果不考虑不同路径重合名等可以这样
    If App.PrevInstance Then
      msgbox "程序已在运行"
    else
    end if 
      

  5.   

    在不同路径情况下可以用FindWindow查找
      

  6.   

    每一个VB工程都有一个APP全局对象,它包含了:应用程序的标题、版本信息、可执行文件和帮助文件的路径及名称以及是否运行前一个应用程序的示例
      

  7.   

    App.PrevInstance 不可靠,随便复制个副本就能运行了。用全局原子或互斥体好点。