例如:
当我双击一个1.exe的文件 怎么样判断它被打开了 如果打开就给个提示~~
当我双击一个1.exe的文件 怎么样判断它被打开了 如果打开就给个提示~~
解决方案 »
- vb 调用dll的问题
- ++高手啊,快来吧!关于GetClassName
- 如何读出一个文件夹下面(包括子文件夹)的所有html文件的<title></title>之间的内容?
- 获取密码的问题,高手们请进来看看。
- 我想把vb程序中的option的值和access连接起来,怎么连接呀?我刚刚学vb,不会编,可是老板追的急,那位帮我解决一下呀
- 袁飞,你这样做是不对的(关于控件的自动下载安装)
- 如何取消vb默认的应用程序忙对话框
- 请各位高人帮忙!万分紧急!!!!!!
- 急! 如何设置一个用户控件
- 提了几个问题了,可是没人能解答??到现在自己都已经没有分了?可是问题又没人能解答?岂不是叫人走投无路吗?
- 请问VB中如何调用外部的可执行文件,并且应许带参数执行?只有10分了
- 用WinSock控件怎么接受大块的数据包 且不会被裁剪
Private Sub Form_Initialize()
If App.PrevInstance Then End
End Sub
Private Sub Form_Initialize()
If App.PrevInstance Then
msgbox "文件已打开"
End
End
End Sub
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
sub form_load()
on error goto ExitUs
sckX.bind aPort 'aPort为一个固定的端口
exit sub
ExitUs:
msgbox "程序已经打开"
end sub
其他格式就不好说了,因为会调用对应的程序来打开文件
--------------------------
文件小的话 不妨先复制一份
然后用Kill 加个on error
如果没有出错没有打开 再把文件写回去
如果出错了就是文件已经被打开了
是有点BT不过应该可以满足你的要求
呵呵,根据进程文件名来判断有没有运行是最好的了哎,都是吃中饭的时间了,饿着肚子写下了下面这个公用函数,在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
然后用Kill 加个on error
如果没有出错没有打开 再把文件写回去
如果出错了就是文件已经被打开了
是有点BT不过应该可以满足你的要求
那倒是不用这么麻烦,直接重命名文件也是一回事。
但有个问题,你用NotePad打开一个txt文件,然后再Kill它,看看结果会怎么样:)
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"都是可以的
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