COMO SABER SE O OUTLOOK ESTA CARREGADO

USUARIO.EXCLUIDOS 16/06/2004 07:49:05
#29844
Como faço para saber através do VB se o Outlook já está sendo executado, ou seja, já está carregado?

USUARIO.EXCLUIDOS 16/06/2004 11:56:52
#29911
Resposta escolhida
Aproveitando a reposta do post http://www.vbmania.com.br/vbmforum.php?varMethod=Abrir&varID=29235&varSubPagina=1&varFiltro=filtro você poderia descobrir se o outlook esta sendo executando pelo nome do programs assim:

Use esse exemplo para testar a função IsRunning.

If IsRunning("outlook.exe") Then
MsgBox "Outlook esta carregado!"
Else
MsgBox "Outlook não esta carregado!"
End If


Coloque o código abaixo num módulo.

Option Explicit

Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const MAX_PATH As Long = 260

Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type

Public Const PROCESS_ALL_ACCESS As Long = &H1F0FFF

Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
(ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Public Declare Function ProcessFirst Lib "kernel32" _
Alias "Process32First" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" _
Alias "Process32Next" _
(ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32" _
(ByVal hPass As Long)

Public Function IsRunning(EXEName As String) As Boolean

Dim hSnapShot As Long
Dim uProcess As PROCESSENTRY32
Dim hProcess As Long

IsRunning = False
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = -1 Then Exit Function

uProcess.dwSize = Len(uProcess)
If ProcessFirst(hSnapShot, uProcess) = 1 Then
Do
If LCase$(Left$(uProcess.szExeFile, InStr(1, uProcess.szExeFile, vbNullChar) - 1)) = LCase$(EXEName) Then
IsRunning = True
Exit Do
End If
Loop While ProcessNext(hSnapShot, uProcess)
End If

Call CloseHandle(hSnapShot)

End Function
Tópico encerrado , respostas não são mais permitidas