请问如何枚举系统中所有的进程名?
解决方案 »
- 格式化时间
- 用SetupFactory7如何把编译好的DLL文件存安装到系统目录下(C:\WINNT\system32)
- 关于socket的阻塞模式和非阻塞模式(使用API非socket对象)
- 急,存储过程中排序规则冲突如何解决?
- 关于picture控件的问题?
- 高分求解呀!!!
- 如何取消rst.addnew的添加操作?
- 各位高手:DataReport报表在Win2000/XP下报表调整纸方向和宽度的方法
- .ini文件有什么用?各位帮忙!
- 通过SYGATE3.11上网的局域网工作站为何不能上WWW.SINA.COM.CN????????????
- 请问这个错误的原因在哪
- 进入一窗体后,窗体不停的抖动是怎么回事,单步执行时正常.
http://www.80diy.com/home/20051108/10/4378494.htmlVB 枚举隐藏进程 http://blog.csdn.net/chenhui530/archive/2007/10/09/1817052.aspx
'**模 块 名:ModFindProcess
'**说 明:进程相关操作
'**创 建 人:马大哈 http://www.m5home.com/
'**日 期:2006年3月18日
'**日 期:2007年1月23日
'**描 述:改进了结束进程的条件,可以根据PID来结束
'**版 本:V1.3
'*************************************************************************
Option ExplicitPublic Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPublic Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const PROCESS_TERMINATE = 1Type 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 TypePrivate Type MyProcess
ExeName As String
PID As Long
End TypePublic Function CloseProcess(Optional ByVal ProName As String, Optional ByVal PID As Long) As Integer
'传入进程名或PID,结束相应进程
Dim tPID As Long
Dim tPHwnd As Long
Dim ProArr() As String, PIDArr() As Long
Dim I As Long
Call ListProcess(ProArr, PIDArr)
For I = 1 To UBound(ProArr)
If PIDArr(I) = PID Or ProArr(I) = ProName Then '配对进程ID或进程名
Exit For
End If
Next I
If I > UBound(PIDArr) Then Exit Function
tPID = PIDArr(I)
tPHwnd = OpenProcess(PROCESS_TERMINATE, False, tPID)
Debug.Print tPHwnd
If tPHwnd Then
CloseProcess = TerminateProcess(tPHwnd, 0)
End If
End FunctionPublic Function FindProcess(ByVal ProName As String, Optional ByRef PID As Long) As Boolean
'传入进程名,如果进程存在,在PID里返回进程ID,函数返回True,否则返回Flase
'ProName: 指定进程名
'PID: 如果进程名存在,返回其PID
'返回值: 进程名存在返回TRUE,否则返回FALSE
Dim ProArr() As String, PIDArr() As Long
Dim I As Long
Call ListProcess(ProArr, PIDArr)
For I = 1 To UBound(ProArr)
If ProArr(I) = ProName Then
PID = PIDArr(I)
FindProcess = True
Exit For
End If
Next I
End FunctionPublic Function ListProcess(ByRef ProExeName() As String, ByRef ProPid() As Long)
'列出进程以及相应PID
'ProExeName(): 进程名
'ProPid(): 相应的PID
Dim MyProcess As PROCESSENTRY32
Dim mySnapshot As Long
Dim ProData() As MyProcess
Dim I As Long
ReDim ProData(0)
MyProcess.dwSize = Len(MyProcess)
mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
ProcessFirst mySnapshot, MyProcess
ReDim Preserve ProData(UBound(ProData) + 1)
ProData(UBound(ProData)).ExeName = Left(MyProcess.szexeFile, InStr(MyProcess.szexeFile, Chr(0)) - 1)
ProData(UBound(ProData)).PID = MyProcess.th32ProcessID
'Debug.Print ProData(UBound(ProData)).ExeName
MyProcess.szexeFile = ""
While ProcessNext(mySnapshot, MyProcess)
ReDim Preserve ProData(UBound(ProData) + 1)
ProData(UBound(ProData)).ExeName = Left(MyProcess.szexeFile, InStr(MyProcess.szexeFile, Chr(0)) - 1)
ProData(UBound(ProData)).PID = MyProcess.th32ProcessID
' Debug.Print ProData(UBound(ProData)).ExeName
MyProcess.szexeFile = ""
Wend
ReDim ProExeName(UBound(ProData))
ReDim ProPid(UBound(ProData))
For I = 1 To UBound(ProData)
With ProData(I)
ProExeName(I) = .ExeName
ProPid(I) = .PID
End With
Next I
End Function
'lArrPID()里面就是对应的PID.
dim Newstr as string
dim i as integer
for i=1 to len(str)
s=mid(str,i,1)
if S<>"" then Newstr=Newstr & s
next 以前,我用API函数GetWindowsDir得到Windows目录时出现过这样的情况,得到的目录是和你设置的缓冲区一样长(比如255),其实多余的都是空格,用Trim()函数就是去不掉。
进程名后面那个不是倒7字的字符,是字符串结束符。