求:VB按钮问题! 按钮控制VBS脚本运行和关闭

来源:百度知道 编辑:UC知道 时间:2024/05/09 20:37:48
我要用VB写个程序
程序里有个按钮(标题为:点击运行), 点一下按钮,会运行一个程序
且点击后,按钮的标题改为 点击关闭。 再点一下按钮,会关闭这个程序。
请问一下这个按钮代码该怎么写???
程序关闭后 按钮的标题又会改为 点击运行!

Private Sub Command1_Click()
f = "d:\a.vbs"

If Command1.Caption = "点击运行" Then
GetObject("", "WScript.Shell").Run """" & f & """"
Command1.Caption = "点击关闭"
Else
f = LCase(f)
For Each p In GetObject("winmgmts:").InstancesOf("win32_process")
If (LCase(p.Name) = "wscript.exe") And (InStr(LCase(p.commandline), f) <> 0) Then
p.Terminate
End If
Next
Command1.Caption = "点击运行"
End If
End Sub

Private Sub Form_Load()
Command1.Caption = "点击运行"
End Sub