vb监视内存任务列表
修改下段程序为:监视遍历进程表,任一exe运行任一exe,即后一个exe的父进程是前一个exe,判断父进程是不是explorer.exe,如果不是就弹出一个msgbox,msgbox包含子进程的名字
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long晕!楼主,你开玩笑啊,这个根本不用试~~~~~~~~
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) 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 * 1024
End Type
Const TH32CS_SNAPPROCESS = &H2
Private Sub Command1_Click()
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim flag As Boolean
Dim mName As String
Dim i As Integer
Dim pid As Long, explorer As Long '注意这2个变量就用来存放2个ID
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) '建立进程快照
'搜索explorer.exe进程,并获得其ID
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then '遍历第一个进程,获得PROCESSENTRY32结构
Do
i = InStr(1, my.szExeFile, Chr(0)) '获得映像名称
mName = LCase(Left(my.szExeFile, i - 1)) '并转换成小写
If mName = "explorer.exe" Then '是不是explorer.exe
explorer = my.th32ProcessID '获得进程ID
ElseIf mName = LCase(App.EXEName & ".exe") Then '是不是自己
pid = my.th32ParentProcessID '获得父进程ID
Else
flag = False
End If
Loop Until (Process32Next(l, my) < 1) '遍历所有进程直到返回值为False
End If
l1 = CloseHandle(l)
End If
If pid <> explorer Then
MsgBox "你被人调戏了!^_^"
End If
End Sub
什么意思? 如果是在VB6环境下,进程是VB6.exe,并非APP.exename,必须生成可执行文件才行。
知道直接运行是vb6.exe啊,生成后运行就不是了啊 shell "pslist -t >c:\pslist.txt",vbHide
'然后读文件c:\pslist.txt的内容
pslist.exe从这里下载
http://technet.microsoft.com/en-us/sysinternals/bb545027.aspx
补充:VB , 基础类