vb代码怎么用

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

Private Sub Command1_Click()
If CheckApplicationIsRun("QQ.exe") = True Then
MsgBox "QQ程序已运行"
Else
MsgBox "QQ程序没有运行"
End If
End Sub

怎么用啊??

我是初学者 VB6.0

详细步骤如下:

    打开VB6.0,选择新建标准 EXE,并点击打开


    在Form1中添加一个CommandButton控件

    双击Command1,进入程序编辑界面,将原来的内容清除,复制上述代码

    按F5运行程序,点击Command1,即可实现程序检测QQ程序是否运行的效果

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-13
先打开VB6,然后在“新建工程”里面选择“标准exe”,点打开。
在窗口左边有那个控件栏,第三排第二个名为commandbutton的就是按钮控件。左键点击,然后整个窗体中间的form1的下面,拉一个按钮。
然后在第一排依次点击“视图“--”代码窗口“,会弹出代码窗口,把这些代码复制进去,然后按F5就可以运行这段代码了。本回答被提问者和网友采纳
第2个回答  2011-07-15
打开VB后,先在窗体上添加一个按钮
然后在窗体上右击鼠标,选择“查看代码”。在代码窗口中,粘贴上述代码。追问

详细点,,,我是新手普