Option Explicit
Private Declare Function PostMessage Lib "User32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long '发送消息,用来关闭指定程序
Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long '查找窗体
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const WM_CLOSE = &H10 '关闭程序
Private Sub Form_Load()
WebBrowser1.Navigate "http://alexa.alexacn.net/ipzhxx.asp"
End Sub
Private Sub Command1_Click()
Sleep 18000000
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "河南网通宽带用户客户端") '找到窗口
Debug.Print winHwnd '用来调试 在立即窗口中输入winhnd
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) '关闭窗口
Sleep 10000
Dim abc
abc = Shell("C:\Program Files\racer-han-cnc\racer.exe", 1)
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Sleep 10000
Dim vDoc, vTag
Dim i As Integer
Set vDoc = WebBrowser1.Document
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Or vTag.Type = "password" Then
ElseIf vTag.Type = "button" Then
vTag.Click
End If
End If
Next i
End Sub
要求是这段
Private Sub Command1_Click()
Sleep 18000000
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "河南网通宽带用户客户端") '找到窗口
Debug.Print winHwnd '用来调试 在立即窗口中输入winhnd
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&) '关闭窗口
Sleep 10000
Dim abc
abc = Shell("C:\Program Files\racer-han-cnc\racer.exe", 1)
End Sub
循环直到程序退出~