USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Miscelâneas)

Título da Dica:  Saber se um programa foi encerrado
Postada em 14/8/2000 por Webmaster      Clique aqui para enviar email para o autor  webmaster@vbweb.com.br
Private Type STARTUPINFO
  cb As Long
  lpReserved As String
  lpDesktop As String
  lpTitle As String
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Long
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type

Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessID As Long
  dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject Lib _
        "Kernel32" (ByVal hHandle As Long, ByVal _
        dwMilliseconds As Long) As Long
Private Declare Function CreateProcessA Lib _
        "Kernel32" (ByVal lpApplicationName As _
        Long, ByVal lpCommandLine As String, _
        ByVal lpProcessAttributes As Long, ByVal _
        lpThreadAttributes As Long, ByVal _
        bInheritHandles As Long, ByVal _
        dwCreationFlags As Long, ByVal _
        lpEnvironment As Long, ByVal _
        lpCurrentDirectory As Long, lpStartupInfo _
        As STARTUPINFO, lpProcessInformation As _
        PROCESS_INFORMATION) As Long
Private Declare Function CloseHandle Lib "Kernel32" _
        (ByVal hObject As Long) As Long

Private Const NORMAL_PRIORITY_CLASS As Long = &H20&
Private Const INFINITE As Long = -1&
Private Const WAIT_FAILED As Long = &hFFFFFFFF
Private Const WAIT_TIMEOUT As Long = &h102&
Private Const STILL_ACTIVE As Long = &h103&

Private Sub Command1_Click()
  Dim lRet&, szCommandLine$
  Dim ProcInfo As PROCESS_INFORMATION
  Dim StartProc As STARTUPINFO
  On Error Resume Next
  szCommandLine$ = "notepad.exe"
  StartProc.cb = Len(StartProc)
  If CreateProcessA(0&, szCommandLine$, 0&, 0&, 1&, _
        NORMAL_PRIORITY_CLASS, 0&, 0&, StartProc, _
        ProcInfo) Then
    'Tá como INFINITE mas pode ser trocado para um
    'valor em milisegundos e IRet& testado com WAIT_FAILED,
    'WAIT_TIMEOUT e STILL_ACTIVE
    lRet& = WaitForSingleObject(ProcInfo.hProcess, INFINITE)
    CloseHandle (ProcInfo.hThread)
    CloseHandle (ProcInfo.hProcess)
    MsgBox "Deu Certo"
  Else
    MsgBox "Deu Erro"
  End If
End Sub
 


CyberWEB Network Ltda.    © Copyright 2000-2017   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página