大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net遍历进程,vbnet遍历控件

用vb.net怎样实现在遍历某一文件夹下的所有文件

'把下面的目录改成你要遍历的目录

成都网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、微信小程序开发、集团成都企业网站定制等服务项目。核心团队均拥有互联网行业多年经验,服务众多知名企业客户;涵盖的客户类型包括:被动防护网等众多领域,积累了大量丰富的经验,同时也获得了客户的一致赞誉!

Dim MyDir = "C:\Windows"

Dim MyInfo = MyDir + "目录下的所有文件包括:"

For Each MyFile In System.IO.Directory.GetFiles(MyDir)

MyInfo += Environment.NewLine + MyFile

Next

Me.RichTextBox1.Text =MyInfo

VB关进程

'你要关闭什么进程

'就写

'Call taskkill("进程名.exe")

'注意大小写啊

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

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_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 Sub taskkill(ByVal taskname As String)

Dim my As PROCESSENTRY32

Dim l As Long

Dim l1 As Long

Dim flag As Boolean

Dim mName As String

Dim i As Integer

l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)

If l Then

my.dwSize = 1060

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

Do

i = InStr(1, my.szExeFile, Chr$(0))

mName = LCase$(Left$(my.szExeFile, i - 1))

If mName = LCase$(taskname) Then

pid = my.th32ProcessID

pname = mName

Dim mProcID As Long

mProcID = OpenProcess(1, -1, pid)

TerminateProcess mProcID, 0

flag = True

Exit Function

Else

flag = False

End If

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

End If

l1 = CloseHandle(l)

End If

End Sub

Private Sub Command1_Click()

Call taskkill("NOTEPAD.EXE")

'这个是关闭记事本进程的

End Sub

这是我回答的 复制自己回答的内容不算复制吧?????

vb.net中如何遍历程序窗体中的控件?并读写控件的数据。

Public Sub GetAllControls(ByVal InContainer As Control, ByRef RecieveList As ListBox)

For i As Integer = 0 To InContainer.Controls.Count - 1

If InContainer.Controls.Item(i).Text  "" Then

GetList.Items.Add(InContainer.Controls.Item(i).Text  vbCrLf)

End If

If InContainer.Controls.Item(i).Controls.Count  0 Then

GetAllControls(InContainer.Controls.Item(i), GetList)

End If

Next

End Sub

这段代码可行,但不能遍历菜单和工具栏,要按需要修改

VB.net的遍历Foreach有什么功能呀。一直看不懂。 能给我解释下图中的语句意思吗?

for each是用来简化for的,但你这种写法有点奇怪,一般没这样用的,通常的用法是

dim a() as string={....}

dim str as string '定义临时变量,它的类型与你数组中元素类型一致

For Each str In a

MessageBox.Show(str)

Next

你上面代码中,a就是一个3个元素的数组,从a[0]到a[2], 用for each的时候,就会遍历你的a数组,上面的代码相当于

for i=0 to a.Length-1

MessageBox.Show(a(i))

next


新闻名称:vb.net遍历进程,vbnet遍历控件
分享地址:http://dzwzjz.com/article/dsgjggs.html
在线咨询
服务热线
服务热线:028-86922220
TOP