vb查找进程名。(电子极域教师的进程)

vb查找进程名。(电子极域教师的进程),第1张

'

'此模块的功能是:

'功能一:

' 查找所有的进程,并将相应的进程关闭

'功能二:

' 将所有的系统当前进程名称存储在数组SystemSoft()中

'

'

'常量、变量、API函数定义区

Public SystemSoft() As String

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" (ByVal hObject As Long) 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

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

Dim pid As Long

Dim pname As String

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 sEndProess1 As String = "1exe" '要关闭的进程名称

'

'

'主要通过调用此子过程来完成前面提到的两个功能

Public Sub SeekShut()

Dim my As PROCESSENTRY32

Dim l As Long

Dim l1 As Long

Dim flag As Boolean

Dim mName As String

Dim i As Integer

Static j As Integer

j = 0

l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)

If l Then

mydwSize = 1060

If (Process32First(l, my)) Then '遍历第一个进程

Do

i = InStr(1, myszExeFile, Chr(0))

mName = LCase(Left(myszExeFile, i - 1))

j = j + 1

ReDim Preserve SystemSoft(j) '重定义程序名称数组并赋值

SystemSoft(j) = mName

If mName = LCase(sEndProess1) Then '

pid = myth32ProcessID

pname = mName

Dim mProcID As Long

mProcID = OpenProcess(1&, -1&, pid)

TerminateProcess mProcID, 0&

flag = True

'Exit Sub '此处若退出,则无法将系统所有进程都保存在数组SystemSoft()中

Else

flag = False

End If

Loop Until (Process32Next(l, my) < 1) '遍历所有进程直到返回值为False

End If

l1 = CloseHandle(l)

End If

End Sub

'

Visual Basic是一种由微软公司开发的包含协助开发环境的事件驱动编程语言。

从任何标准来说,VB都是世界上使用人数最多的语言——不仅是盛赞VB的开发者还是抱怨VB的开发者的数量。

源自于BASIC编程语言。VB拥有图形用户界面(GUI)和快速应用程序开发(RAD)系统,可以轻易的使用DAO、RDO、ADO连接数据库,或者轻松的创建ActiveX控件。程序员可以轻松的使用VB提供的组件快速建立一个应用程序。

一个command 一个list。  list中第一个任务管理器,与最后一个Program Manager 过滤不掉 。

如果想过滤的话 可以在窗体中添加一个判断,来移除。

这是获取程序

Process[] ps=ProcessGetProcesses();

foreach (Process p in ps)

{

if (pMainWindowHandle != null)

{

richTextBox1Text += pMainWindowTitle + "";

}

}

#region 查找所有应用程序标题 private const int GW_HWNDFIRST = 0;

private const int GW_HWNDNEXT = 2;      

private const int GWL_STYLE = (-16);      

private const int WS_VISIBLE = 268435456;      

private const int WS_BORDER = 8388608;      

#region AIP声明        

[DllImport("IpHlpApidll")]        

extern static public uint GetIfTable(byte[] pIfTable, ref uint pdwSize, bool bOrder);      

[DllImport("User32")]        

private extern static int GetWindow(int hWnd, int wCmd);

[DllImport("User32")]        

private extern static int GetWindowLongA(int hWnd, int wIndx);

[DllImport("user32dll")]        

private static extern bool GetWindowText(int hWnd, StringBuilder title, int maxBufSize);        

[DllImport("user32", CharSet = CharSetAuto)]        

private extern static int GetWindowTextLength(IntPtr hWnd);      

#endregion      

/// <summary>      

/// 查找所有应用程序标题      

/// </summary>      

/// <returns>应用程序标题范型</returns>      

public static List<string> FindAllApps(int Handle)

{          

List<string> Apps = new List<string>();          

int hwCurr;            

hwCurr = GetWindow(Handle, GW_HWNDFIRST);          

while (hwCurr > 0)          

{                

int IsTask = (WS_VISIBLE | WS_BORDER);                

int lngStyle = GetWindowLongA(hwCurr, GWL_STYLE);              

bool TaskWindow = ((lngStyle & IsTask) == IsTask);              

if (TaskWindow)              

{                    

int length = GetWindowTextLength(new IntPtr(hwCurr));

StringBuilder sb = new StringBuilder(2 length + 1);                  

GetWindowText(hwCurr, sb, sbCapacity);                  

string strTitle = sbToString();                

if (!stringIsNullOrEmpty(strTitle))                  

{                        

AppsAdd(strTitle);                  

}              

}                

hwCurr = GetWindow(hwCurr, GW_HWNDNEXT);          

}

return Apps;      

}        

#endregion

调用

private void btReApp_Click(object sender, EventArgs e)      

{            

LvAppItemsClear();            

List<string> Apps = SystemInfoFindAllApps((int)thisHandle);          

foreach (string app in Apps)          

{                

ListViewItem item = new ListViewItem(app);              

LvAppItemsAdd(item);          

}      

}

您好,我看到您的问题很久没有人来回答,但是问题过期无人回答会被扣分的并且你的悬赏分也会被没收!所以我给你提几条建议 一,你可以选择在正确的分类下去提问,这样知道你问题答案的人才会多一些,回答的人也会多些。 二,您可以到与您问题相关专业网站论坛里去看看,那里聚集了许多专业人才,一定可以为你解决问题的。 三,你可以向你的网上好友问友打听,他们会更加真诚热心为你寻找答案的,甚至可以到相关网站直接搜索 四,网上很多专业论坛以及知识平台,上面也有很多资料,我遇到专业性的问题总是上论坛求解决办法的。 五,将你的问题问的细一些,清楚一些!让人更加容易看懂明白是什么意思 谢谢采纳我的建议

shell "taskmgrexe",1

你说是这样打开?

sub command1_click()

shell "taskmgrexe",1

end sub

====================

//提高10分悬赏

10分很多吗?

=================

拿点陈年旧货出来吧

第一段,可以取得当前进程列表

'模块

Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

'该函数是EnumWindows的回调函数,EnumWindows函数将遍历的窗口句柄传递到hwnd参数中

Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long

Dim astr As String 256

Dim l As Long

l = GetWindowText(hwnd, astr, Len(astr))

If InStr(astr, " ") > 1 Then

Form1List1AddItem astr

End If

EnumWindowsProc = True

End Function

'窗体

Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Sub Command1_Click()

Dim l As Long

List1Clear

'遍历所有的窗口

l = EnumWindows(AddressOf EnumWindowsProc, 0)

End Sub

第二段,可以取到进程的路径

CSDN _ FAQ列表 _ 基础类 _ VB 与 API

Q : 如何列举所有正在运行的进程

主要解答者: SoHo_Andy 提交人: leonhome

感谢: SoHo_Andy、rainstormmaster、wu_yongcai

审核者: online 论坛对应贴子: 查看

A :

:)

---------------------------------------------------------------

模块:

Option Explicit

Public Declare Function Process32First Lib "kernel32" ( _

ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long

Public Declare Function Process32Next Lib "kernel32" ( _

ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long

Public Declare Function CloseHandle Lib "Kernel32dll" _

(ByVal Handle As Long) As Long

Public Declare Function OpenProcess Lib "Kernel32dll" _

(ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _

ByVal dwProcId As Long) As Long

Public Declare Function EnumProcesses Lib "psapidll" _

(ByRef lpidProcess As Long, ByVal cb As Long, _

ByRef cbNeeded As Long) As Long

Public Declare Function GetModuleFileNameExA Lib "psapidll" _

(ByVal hProcess As Long, ByVal hModule As Long, _

ByVal ModuleName As String, ByVal nSize As Long) As Long

Public Declare Function EnumProcessModules Lib "psapidll" _

(ByVal hProcess As Long, ByRef lphModule As Long, _

ByVal cb As Long, ByRef cbNeeded As Long) As Long

Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _

ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long

Public Declare Function GetVersionExA Lib "kernel32" _

(lpVersionInformation As OSVERSIONINFO) As Integer

Public Type PROCESSENTRY32

dwSize As Long

cntUsage As Long

th32ProcessID As Long ' This process

th32DefaultHeapID As Long

th32ModuleID As Long ' Associated exe

cntThreads As Long

th32ParentProcessID As Long ' This process's parent process

pcPriClassBase As Long ' Base priority of process threads

dwFlags As Long

szExeFile As String 260 ' MAX_PATH

End Type

Public Type OSVERSIONINFO

dwOSVersionInfoSize As Long

dwMajorVersion As Long

dwMinorVersion As Long

dwBuildNumber As Long

dwPlatformId As Long '1 = Windows 95

'2 = Windows NT

szCSDVersion As String 128

End Type

Public Const PROCESS_QUERY_INFORMATION = 1024

Public Const PROCESS_VM_READ = 16

Public Const MAX_PATH = 260

Public Const STANDARD_RIGHTS_REQUIRED = &HF0000

Public Const SYNCHRONIZE = &H100000

'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF

Public Const PROCESS_ALL_ACCESS = &H1F0FFF

Public Const TH32CS_SNAPPROCESS = &H2&

Public Const hNull = 0

Function StrZToStr(s As String) As String

StrZToStr = Left$(s, Len(s) - 1)

End Function

Public Function getVersion() As Long

Dim osinfo As OSVERSIONINFO

Dim retvalue As Integer

osinfodwOSVersionInfoSize = 148

osinfoszCSDVersion = Space$(128)

retvalue = GetVersionExA(osinfo)

getVersion = osinfodwPlatformId

End Function

窗体:(一个按钮,一个listbox,如果不需要显示可设为不可见)

Option Explicit

Private Sub Command1_Click()

List1Clear

Select Case getVersion()

Case 1 'Windows 95/98

Dim f As Long, sname As String

Dim hSnap As Long, proc As PROCESSENTRY32

hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)

If hSnap = hNull Then Exit Sub

procdwSize = Len(proc)

' Iterate through the processes

f = Process32First(hSnap, proc)

Do While f

sname = StrZToStr(procszExeFile)

List1AddItem sname

f = Process32Next(hSnap, proc)

Loop

Case 2 'Windows NT

Dim cb As Long

Dim cbNeeded As Long

Dim NumElements As Long

Dim ProcessIDs() As Long

Dim cbNeeded2 As Long

Dim NumElements2 As Long

Dim Modules(1 To 200) As Long

Dim lRet As Long

Dim ModuleName As String

Dim nSize As Long

Dim hProcess As Long

Dim i As Long

'Get the array containing the process id's for each process object

cb = 8

cbNeeded = 96

Do While cb <= cbNeeded

cb = cb 2

ReDim ProcessIDs(cb / 4) As Long

lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)

Loop

NumElements = cbNeeded / 4

For i = 1 To NumElements

'Get a handle to the Process

hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _

Or PROCESS_VM_READ, 0, ProcessIDs(i))

'Got a Process handle

If hProcess <> 0 Then

'Get an array of the module handles for the specified

'process

lRet = EnumProcessModules(hProcess, Modules(1), 200, _

cbNeeded2)

'If the Module Array is retrieved, Get the ModuleFileName

If lRet <> 0 Then

ModuleName = Space(MAX_PATH)

nSize = 500

lRet = GetModuleFileNameExA(hProcess, Modules(1), _

ModuleName, nSize)

List1AddItem Left(ModuleName, lRet)

End If

End If

'Close the handle to the process

lRet = CloseHandle(hProcess)

Next

End Select

MsgBox IsRun("winamp的路径")

End Sub

Private Function IsRun(ByVal filename As String) As Boolean

Dim i As Long

IsRun = False

For i = 1 To List1ListCount

DebugPrint List1List(i)

If List1List(i) = UCase(filename) Then

IsRun = True

Exit Function

End If

Next

End Function

===============

我都试过,都能用

'定义正则表达式

Dim objRegExp As RegExp

Set objRegExp = New RegExp

objRegExpPattern = "111"

'查找系统的所有进程

Dim allProcs As Process() = ProcessGetProcesses()

'对每个找到的进程名,匹配正则表达式,如果能匹配,则kill掉

For Each proc as Process in allProcs

if (objRegExpTest(procProcessName) = True) then

prockill()

end if

Next

以上就是关于vb查找进程名。(电子极域教师的进程)全部的内容,包括:vb查找进程名。(电子极域教师的进程)、vb如何获取任务管理器中应用程序列表、vb 获取指定进程个数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9327465.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存