例如:
当我双击一个1.exe的文件 怎么样判断它被打开了 如果打开就给个提示~~

解决方案 »

  1.   

    我们希望防止同一应用程序同时执行多次,其方法是判断App的PrevInstance属性若App.PrevInstance为True,则表示此应用程序在执行中,可以直接结束本此执行,这样就可以了。 
    Private Sub Form_Initialize() 
     If App.PrevInstance Then End
    End Sub
      

  2.   

    你要给个提示,也简单
    Private Sub Form_Initialize() 
     If App.PrevInstance Then 
          msgbox "文件已打开"
          End
      End
    End Sub
      

  3.   

    On Error Resume Next
    Dim a As Byte
    Open "1.exe" For Binary As #1
    Get 1, 1, a
    Put 1, 1, a
    If Err.Number <> 0 Then MsgBox "已打开"
    Close #1
      

  4.   

    如 laisiwei(.:RNPA:.刺猬)所述~
      

  5.   

    基本上不可以,如果别的程序以只读不加锁的方式打开某个文件,laisiwei(.:RNPA:.刺猬)的方法是不会出错的
      

  6.   

    用winsock 自己也汗...
    sub form_load()
    on error goto ExitUs
         sckX.bind aPort 'aPort为一个固定的端口
         exit sub
    ExitUs:
         msgbox "程序已经打开"
    end sub
      

  7.   

    exe你可以检查下进程试试.
    其他格式就不好说了,因为会调用对应的程序来打开文件
      

  8.   

    之前看错问题了不好意思
    --------------------------
    文件小的话 不妨先复制一份
    然后用Kill 加个on error
    如果没有出错没有打开 再把文件写回去
    如果出错了就是文件已经被打开了
    是有点BT不过应该可以满足你的要求
      

  9.   


    呵呵,根据进程文件名来判断有没有运行是最好的了哎,都是吃中饭的时间了,饿着肚子写下了下面这个公用函数,在VB6,Win2000上测试通过,你可以直接加入到工程中去用便可.记得:在工程中引用 WMI:代码:Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
        On Error GoTo Err
        Dim WMI
        Dim Obj
        Dim Objs
        CheckApplicationIsRun = False
        Set WMI = GetObject("WinMgmts:")
        Set Objs = WMI.InstancesOf("Win32_Process")
        For Each Obj In Objs
            If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
               CheckApplicationIsRun = True
               If Not Objs Is Nothing Then Set Objs = Nothing
               If Not WMI Is Nothing Then Set WMI = Nothing
               Exit Function
            End If
        Next
        If Not Objs Is Nothing Then Set Objs = Nothing
        If Not WMI Is Nothing Then Set WMI = Nothing
        Exit Function
    Err:
        If Not Objs Is Nothing Then Set Objs = Nothing
        If Not WMI Is Nothing Then Set WMI = Nothing
    End FunctionPrivate Sub Command1_Click()
        If CheckApplicationIsRun("notepad.exe") = True Then
           MsgBox "已经运行了记事本程序"
        Else
           MsgBox "记事本程序没有运行"
        End If
        
        If CheckApplicationIsRun("1.exe") = True Then
           MsgBox "已经运行了1.exe程序"
        Else
           MsgBox "1.exe程序没有运行"
        End If
    End Sub
      

  10.   

    //文件小的话 不妨先复制一份
    然后用Kill 加个on error
    如果没有出错没有打开 再把文件写回去
    如果出错了就是文件已经被打开了
    是有点BT不过应该可以满足你的要求
    那倒是不用这么麻烦,直接重命名文件也是一回事。
    但有个问题,你用NotePad打开一个txt文件,然后再Kill它,看看结果会怎么样:)
      

  11.   

    To  laisiwei(.:RNPA:.刺猬) :   你的方法不行啊,要是exe没有运行,你那程序会把exe文件改写的回复人: kinpoo(波)      你的方法也不对,用Kill这种办法是不是太老土了?方向不对下面我把函数又改了下,参数可以是可执行程序文件名,也可以是整个路径,很灵活Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
        On Error GoTo Err
        Dim WMI
        Dim Obj
        Dim Objs
        CheckApplicationIsRun = False
        Set WMI = GetObject("WinMgmts:")
        Set Objs = WMI.InstancesOf("Win32_Process")
        For Each Obj In Objs
            If InStr(Obj.Description, ".") <> 0 Then
               If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
                   CheckApplicationIsRun = True
                   MsgBox Obj.Description
                   If Not Objs Is Nothing Then Set Objs = Nothing
                   If Not WMI Is Nothing Then Set WMI = Nothing
                   Exit Function
               End If
            End If
        Next
        If Not Objs Is Nothing Then Set Objs = Nothing
        If Not WMI Is Nothing Then Set WMI = Nothing
        Exit Function
    Err:
        If Not Objs Is Nothing Then Set Objs = Nothing
        If Not WMI Is Nothing Then Set WMI = Nothing
    End Function
    如:CheckApplicationIsRun "notepad.exe"
    CheckApplicationIsRun "c:\winnt\system32\notepad.exe"都是可以的
      

  12.   

    呵呵,上面忘记去掉MsgBox了:(引用WMI)Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
        On Error GoTo Err
        Dim WMI
        Dim Obj
        Dim Objs
        CheckApplicationIsRun = False
        Set WMI = GetObject("WinMgmts:")
        Set Objs = WMI.InstancesOf("Win32_Process")
        For Each Obj In Objs
            If InStr(Obj.Description, ".") <> 0 Then
               If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
                   CheckApplicationIsRun = True
                   If Not Objs Is Nothing Then Set Objs = Nothing
                   If Not WMI Is Nothing Then Set WMI = Nothing
                   Exit Function
               End If
            End If
        Next
        If Not Objs Is Nothing Then Set Objs = Nothing
        If Not WMI Is Nothing Then Set WMI = Nothing
        Exit Function
    Err:
        If Not Objs Is Nothing Then Set Objs = Nothing
        If Not WMI Is Nothing Then Set WMI = Nothing
    End Function
      

  13.   

    不好意思 刚学VB不就 感觉VB挺乱的 慢慢学吧