网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vb.netkill的简单介绍

vb.net中,Kill和Shell("del xxxx /f /q")这两个语句哪个更强力?

你可以直接用VB的Kill命令来删除文件:

成都创新互联主要从事做网站、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务化州,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575

Kill "C:\Program Files\3000soft\Red Spider\REDAgent.exe"

一定要用del的话则这样:

Shell "cmd /c del 'C:\Program Files\3000soft\Red Spider\REDAgent.exe'"

补充说一下:你要给整个路径加引号,而不是给每个文件夹名加引号!另外,在字符串内,要用单引号,或者用两个双引号来代表一个双引号,比如:

Shell "cmd /c del ""C:\Program Files\3000soft\Red Spider\REDAgent.exe"""

怎样才能用VB.NET的代码来关闭一个在运行的程序

软糖来回答罗:通过System.Diagnostics命名空间下的Process类来关闭程序的进程

Dim 进程集合 = Process.GetProcessesByName("进程名称")

For Each 进程 In 进程集合

进程.Kill()

'进程.Close() '或者使用关闭

Next

也可以先获取所有进程,再来判断这些进程的名称ProcessName

Dim 获取本地所有进程 = Process.GetProcesses()

For Each 进程 In 获取本地所有进程

If 进程.ProcessName = "explorer.exe" Then 进程.Kill()

Next

vb.net 怎么结束进程

好像不难吧?

我放进了Button1的Click事件里。

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

On Error GoTo Errmessages '在做系统操作时加排错标签是个好习惯

Dim TargetName As String = "ibmdict" '存储进程名为文本型,注:进程名不加扩展名

Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '从进程名获取进程

Dim TargetPath As String '存储进程路径为文本型

If TargetKill.Length 1 Then '判断进程名的数量,如果同名进程数量在2个以上,用For循环关闭进程。

For i = 0 To TargetKill.Length - 1

TargetPath = TargetKill(i).MainModule.FileName

TargetKill(i).Kill()

Next

ElseIf TargetKill.Length = 0 Then '判断进程名的数量,没有发现进程直接弹窗。不需要的,可直接删掉该If子句

MsgBox("没有发现进程!")

Exit Sub

ElseIf TargetKill.Length = 1 Then '判断进程名的数量,如果只有一个,就不用For循环

TargetKill(0).Kill()

End If

MsgBox("已终止" TargetKill.Length "个进程") '弹窗提示已终止多少个进程

Errmessages: ‘定义排错标签

If Err.Description Nothing Then ’判断有无错误,如果有,则 ↓

MsgBox(Err.Description) '当出现错误时,弹窗提示

End If

End Sub

可根据需要自行修改,这个备注够完善了吧?不会的再Hi我。

vb.net中如何结束一个线程

vb.net中如何结束一个线程

一般而言,如果您想终止一个线程,您可以使用System.Threading.Thread类的Abort方法. 例如:

Dim worker As ThreadStart = New ThreadStart(AddressOf workerthreadmethod)

Dim t As Thread = New Thread(worker)

t.Start()

MessageBox.Show("Wait for a while for the thread to start.")

MessageBox.Show(t.ThreadState.ToString())

t.Abort()

MessageBox.Show(t.ThreadState.ToString())

t.Join()

MessageBox.Show(t.ThreadState.ToString())

当然,在调用Abort方法后,线程并不是立刻终止,要等线程的所有finally快中的代码完成后才会完全终止. 所以在主线程中可以用Join方法来同步,当线程还未完全终止时,t.Join()将处于等待,直到t线程完全结束后再继续执行后面的语句。

Abort方法是会导致线程跳出一个异常错误的,你需要在代码中捕获该异常。下面是一个比较完整的VB.NET线程例子:

Imports System

Imports System.Threading

Public Class MyTestApp

Public Shared Sub Main()

Dim t As New Thread(New ThreadStart(AddressOf MyThreadMethod))

'Start the thread

t.Start()

MsgBox("Are you ready to kill the thread?")

'Kill the child thread and this will cause the thread raise an exception

t.Abort()

' Wait for the thread to exit

t.Join()

MsgBox("The secondary thread has terminated.")

End Sub

Shared Sub MyThreadMethod()

Dim i As Integer

Try

Do While True

Thread.CurrentThread.Sleep(1000)

Console.WriteLine("This is the secondary thread running.")

Loop

Catch e As ThreadAbortException

MsgBox("This thread is going to be terminated by the Abort method in the Main function")

End Try

End Sub

End Class

Thread.Abort()方法用来永久销毁一个线程,而且将抛出ThreadAbortException异常。使终结的线程可以捕获到异常但是很难控制恢复,仅有的办法是调用Thread.ResetAbort()来取消刚才的调用,而且只有当这个异常是由于被调用线程引起的异常。因此,A线程可以正确的使用Thread.Abort()方法作用于B线程,但是B线程却不能调用Thread.ResetAbort()来取消Thread.Abort()操作。

vb.net代码结束任务管理器中正在运行的程序

'Imports System.Diagnostics

'测试可以关闭记事本

Dim ps As Process() = Process.GetProcessesByName("notepad")

For Each p As Process In ps

p.Kill()

Next

vb.net 如何结束进程?

Public Sub KillProcessFromMemorry()

'注意进程名称的大小写

Dim procName As String = "EXCEL"

For Each proc In Process.GetProcesses

If proc.ProcessName Like procName Then

Console.WriteLine("'{0}' is running, do you want to quit?(y, n)", procName)

If Console.ReadKey.Key = ConsoleKey.Y Then

proc.Kill()

End If

End If

Next

End Sub


文章名称:vb.netkill的简单介绍
URL地址:http://bjjierui.cn/article/higcip.html

其他资讯