Office中国论坛/Access中国论坛

标题: [求助]关闭一个程序 [打印本页]

作者: dv菜鸟    时间: 2007-1-25 01:46
标题: [求助]关闭一个程序
请各位帮个忙,我想用VBA代码判断一个程序是否运行,如果运行就关闭它。该怎么做?

比如说判断QQ是否运行,如果运行就关闭QQ.exe要怎么做?
作者: 一点通    时间: 2007-1-25 04:08
病毒行为
作者: andymark    时间: 2007-1-25 04:24
用进程判断
作者: dv菜鸟    时间: 2007-1-25 18:29
要怎么做呢?版主可以给段示例代码吗?
作者: dv菜鸟    时间: 2007-1-29 00:10
求助,一点通和andymark两位大师

可以帮忙指导一下吗?急需使用啊
作者: andymark    时间: 2007-1-29 04:14
http://www.office-cn.net/forum.php?mod=viewthread&tid=47065&replyID=34966&skin=1
作者: dv菜鸟    时间: 2007-1-29 18:03
谢谢andymar版主

好佩服啊
作者: wu8313    时间: 2007-1-30 04:40
如果要关闭某个正在打开的文件,可以使用如下代码,是我网上找的。

'原理:先用FindWindow找到程序窗体,然后用SendMessage向这个窗口应答。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "ostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MINIMIZE = &HF020&
Private Const WM_CLOSE = &H10
Private Declare Function DestroyWindow Lib "user32" (ByVal hWnd As Long) As Long
Dim windowsH As Long




Public Sub close_excelfile()


'关闭正在打开的文件,只要获取到 指定文件的caption就可以办到




    a = FindWindow(vbNullString, "microsoft excel - 台帐.xls")
    Debug.Print a
    b = PostMessage(a, WM_CLOSE, 0, 0)
    Debug.Print b
   


End Sub


[此贴子已经被作者于2007-1-29 20:40:54编辑过]






欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3