继续上个问题(vb 关闭当前文件夹下TXT文档中指定的多个进程)

txt一行一个进程名在程序运行后,对比test.txt中的进程名,在程序主界面列出正在运行的进程,并可以复选框取消。oaita的回答差不多了,但主界面显示的是test.t... txt一行一个进程名
在程序运行后,对比test.txt中的进程名,在程序主界面列出正在运行的进程,并可以复选框取消。
oaita的回答差不多了,但主界面显示的是test.txt中所有的记载的进程,我的意思是如果peer.exe没有运行,则不需要在主界面显示。还差一步,谢谢了!
展开
 我来答
oaita
2010-07-07 · TA获得超过708个赞
知道小有建树答主
回答量:669
采纳率:100%
帮助的人:810万
展开全部
把以下代码粘贴到记事本,然后另存为 form1.frm
然后打开运行即可

根据你的补充修改,也不加分……

VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4320
ClientLeft = 60
ClientTop = 345
ClientWidth = 7995
LinkTopic = "Form1"
ScaleHeight = 4320
ScaleWidth = 7995
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtName
Height = 345
Index = 0
Left = 300
TabIndex = 1
Top = 180
Visible = 0 'False
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "结束选中进程"
Height = 525
Left = 6060
TabIndex = 0
Top = 3480
Width = 1245
End
Begin VB.CheckBox chkName
Height = 345
Index = 0
Left = 1500
TabIndex = 2
Top = 180
Visible = 0 'False
Width = 315
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
Dim i As Long
For i = 1 To chkName.UBound
If chkName(i).Value = vbChecked Then
'如果选中则结束该进程
Call endTask(txtName(i).Text)
DoEvents
End If
Next
End Sub

Private Sub Form_Load()
Dim str As String
Open "c:\test.txt" For Input As #1
Dim k As Long
While Not EOF(1)
Line Input #1, str
'每一行是一个进程名
If CheckApplicationIsRun(str) Then
'如果一个进程正在运行
k = k + 1
Load txtName(k)
Load chkName(k)
txtName(k).Move txtName(k - 1).Left, txtName(k - 1).Top + txtName(k - 1).Height
chkName(k).Move chkName(k - 1).Left, chkName(k - 1).Top + chkName(k - 1).Height
txtName(k).Visible = True
chkName(k).Visible = True
txtName(k).Text = str
End If

Wend

Close #1

End Sub

Private Sub endTask(ByVal task As String)
'结束该进程
Dim str As String
str = "taskkill /f /t /im " & task
Shell str, vbHide

End Sub

Function CheckApplicationIsRun(ByVal szExeFileName As String) As Boolean
On Error GoTo Err
Dim WMI
Dim Obj
Dim Objs
CheckApplicationIsRun = False
Set WMI = GetObject("WinMgmts:")
Set Objs = WMI.InstancesOf("Win32_Process")
For Each Obj In Objs
If InStr(UCase(szExeFileName), UCase(Obj.Description)) <> 0 Then
CheckApplicationIsRun = True
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
Exit Function
End If
Next
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
Exit Function
Err:
If Not Objs Is Nothing Then Set Objs = Nothing
If Not WMI Is Nothing Then Set WMI = Nothing
End Function
4xguys
2010-07-05 · TA获得超过241个赞
知道小有建树答主
回答量:423
采纳率:0%
帮助的人:0
展开全部
shell "cmd /c taskkill /im "& text1 & " /f"
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式