高手请进

yAnGmU_373 2006-02-11 07:14:25
如何用VB查看某个程序(进程)是否在运行中?
谢助!!!!!!!!!!!
...全文
65 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
faysky2 2006-02-11
  • 打赏
  • 举报
回复
可以先转换成大写或小写再判断:
If UCase(mName) = UCase("iexplore.exe") Then '通过进程名判断某个进程是否存在运行

If LCase(mName) = LCase("iexplore.exe") Then '通过进程名判断某个进程是否存在运行
yAnGmU_373 2006-02-11
  • 打赏
  • 举报
回复
大哥太感谢了
yAnGmU_373 2006-02-11
  • 打赏
  • 举报
回复
知道了 谢谢 是小写
yAnGmU_373 2006-02-11
  • 打赏
  • 举报
回复
那 word 的进程名是什么?
我该了 不好用
faysky2 2006-02-11
  • 打赏
  • 举报
回复
代码改一下就可以了:

Option Explicit

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ExitProcess Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Const LOCALE_STIMEFORMAT = &H1003
Private Const LOCALE_SSHORTDATE = &H1F
Private Const WM_SETTINGCHANGE = &H1A
Private Const HWND_BROADCAST = &HFFFF&

Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

'***************************************

'获得进程的句柄
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
'终止进程
Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, _
ByVal uExitCode As Long) As Long
'创建一个系统快照
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, lProcessID As Long) As Long
'获得系统快照中的第一个进程的信息
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" _
(ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long
'获得系统快照中的下一个进程的信息
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" _
(ByVal mSnapShot As Long, uProcess As PROCESSENTRY32) As Long

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 * 260&
End Type
Private Const TH32CS_SNAPPROCESS As Long = 2&
Dim mresult


Private Sub Command1_Click()
Dim uProcess As PROCESSENTRY32
Dim mSnapShot As Long
Dim mName As String
Dim i As Integer
Dim flag As Boolean
flag = False
DoEvents
uProcess.dwSize = Len(uProcess)
mSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If mSnapShot Then
mresult = ProcessFirst(mSnapShot, uProcess)
Do While mresult
i = InStr(1, uProcess.szexeFile, Chr(0))
mName = LCase$(Left$(uProcess.szexeFile, i - 1))
If mName = "iexplore.exe" Then '通过进程名判断某个进程是否存在运行
flag = True
MsgBox "ie进程在运行!"
Exit Do
End If
mresult = ProcessNext(mSnapShot, uProcess)
Loop
End If
If flag = False Then
MsgBox "ie进程没有运行!"
End If
End Sub

yAnGmU_373 2006-02-11
  • 打赏
  • 举报
回复
如果要是指定判断某个进程呢?
faysky2 2006-02-11
  • 打赏
  • 举报
回复
判断进程是否存在
http://community.csdn.net/Expert/topic/4531/4531869.xml?temp=.8896448

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧