怎样阻止程序被重复打开,就是确定只让一个程序在运行者?

解决方案 »

  1.   

    private sub form_load()
        If App.PrevInstance Then
            MsgBox "该程序已经运行!", vbInformation
            end
        End If
    end sub
      

  2.   

    虽然我慢了一步,但还是要贴一下,聊表心意,呵呵。If App.PrevInstance = True Then
        MsgBox "本程序已经运行了", vbExclamation Or vbOKOnly, "警告"
        End
    End If
      

  3.   

    If App.PrevInstance Then
           MsgBox "此程式已在執行中...!", vbExclamation, App.ProductName
           End
    End If
      

  4.   

    If App.PrevInstance = True Then
        MsgBox "本程序运行中,请确认重试", VBOKOnly, "出错"
        End
    End If
      

  5.   

    If App.PrevInstance = True Then
        MsgBox "本程序已经运行了", vbExclamation Or vbOKOnly, "警告"
        End
    End If
      

  6.   

    呵呵,以上各位兄弟的程序只能在一定条件下生效。
    如果同一 exe 有两个文件(在不同的目录下)同时运行,上面的代码阻止不了。
    到最后还是要用到 api 的 findwindow 。如果要求不特殊,App.PrevInstance = True 也够了。
      

  7.   

    抢分的来了.
    Form_Load()
       If App.PrevInstance Then End
    End Sub另外 fxy_2002(阿勇) :"如果同一 exe 有两个文件(在不同的目录下)同时运行,上面的代码阻止不了"好象没有这种事发生.我试验的结果是照样不会运行第2个实例(除非你改了工程的名字)
      

  8.   

    同意  fxy_2002(阿勇) 同一个程序,放不同目录就没用了,你可以试试。
      

  9.   

    楼上的是什么OS?我用XP,就是自己做的软件,放到不同的目录中,都可以启动。(同一目录不启动)这句话已放到sub Main()中的第一句了。
    App.PrevInstance Then End 
    你现在在试试,呵呵
      

  10.   

    我上面回复中的“楼上”是指 WallesCai(WallesCai) 
    大家顶得太快了
      

  11.   

    If App.PrevInstance = True Then
        MsgBox "程序已经运行!", VBOKOnly, "警告"
        End
    End If
      

  12.   

    App.PrevInstance的方法只能对同一目录同一文件的程序起作用而真正要做到不重复打开的话只能用Findwindow
      

  13.   

    private sub from_load()
        If App.PrevInstance Then
            MsgBox "该程序已经运行!", vbInformation
            end
        End If
    end sub
    或者
    sub main()
        If App.PrevInstance Then
            MsgBox "该程序已经运行!", vbInformation
            end
        End If
    end sub
      

  14.   

    在主程序中的窗体:
    private sub form_load()
        If App.PrevInstance Then
            MsgBox "该程序已经运行!", vbInformation
            end
        End If
    end sub
      

  15.   

    我还想知道,能不能不用
    If App.PrevInstance Then
            MsgBox "该程序已经运行!", vbInformation
            end
        End If
    而是
    If App.PrevInstance Then
           ‘把之前已经打开的程序提到最前面来。不知怎么实现。难道要用findwindow吗?
            end
        End If
      

  16.   

    使用内存影射文件。发现有退出。否则运行。全局对象也行。
    建议多看看win32编程。