在vb程序中检测www.exe文件,如果发现运行了www.exe程序,则主程序不能退出,在线等
检测www.exe是否运行的函数是什么?在线等啊,急
[解决办法]
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32 " (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32 " (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32 " (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
sub checkf()
Dim r As Long
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
Do While r
If Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0)) = "www.exe " Then
MsgBox "www.exe已经打开! "
End If
r = Process32Next(hSnapShot, uProcess)
Loop
end sub
[解决办法]
添加这个模块到工程:
http://www.m5home.com/bbs/dispbbs.asp?boardID=10&ID=745&page=1
然后:
'查找进程
if FindProcess( "qq.exe ")=true then
msgbox "QQ进程存在! "
end if
'结束进程
CloseProcess "qq.exe "
[解决办法]
程序名随便可以更改
倒不如用FindWindow,检测窗口类名或窗口标题都是个不错的选择