用VB.NET获得系统进程列表-.Net技术-3P代码网
繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> 算法/线程 >> 用VB.NET获得系统进程列表

用VB.NET获得系统进程列表

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:29  文字大小:【】【】【
简介:Retrieving information on system resources and process information was not possible wihtout API calls in VB6. Calling API functions has its own difficulties. Identifying correct datatypes, Identif...
关键字:进程 系统 NET VB

Retrieving information on system resources and process information was not possible wihtout API calls in VB6. Calling API functions has its own difficulties. Identifying correct datatypes, Identifying the API functions, having ErrorHandles to avoid app Crashes are some of those..

VB.NET relieves us from all such problems by providing class libraries to access system resources and environment information. Here is a simple example In VB.NET, that depicts the method to get the list of of processes that are currently running in your system.

1) Place a button in the form

2) Place a TextBox in the Form and name it as txtProcesses

3) Set the Multi-line property of the TextBox(txtProcesses) to True

4) Import the System namespace

5) Write the following code in the CommandButton click Event

Dim sProcesses() As System.Diagnostics.Process

Dim sProcess As System.Diagnostics.Process

Dim s As String

On Error Goto ErrorHandler

sProcesses = System.Diagnostics.Process.GetProcesses()

s = ""

s = vbCrLf & "Procss Info " & vbCrLf

For Each sProcess In sProcesses

s = s & sProcess.Id & Space(5) & sProcess.ProcessName() & vbCrLf

Next

txtProcesses.Text = s

ErrorHandler:

MsgBox "Unexpected Error occurred"

System.Diagnostics.Process is NameSpace provides the method GetProcesses() to get the list of process running in your system. This function returns Object array of type Process. The ID and ProcessName properties of the Process object can be used to retrive the ProcessID(PID) and the Name process.

The overloaded function GetProcesses with << System Name >> parameter can be invoked to get list of processes running in a remote system.

Happy programming with VB.NET.

责任编辑:admin
相关文章