I noticed that the path should (/must) have quotes.
code for onconnection, cut from addinmon doc (sligtly modified with quotes)
....
If IsAddInMonProcess = False Then
'Launch AddInMonitor, supplying Add-In ProgID, Outlook PID,
ThreadID
Dim s As String
s = """" & App.Path & "\AddInMon.exe"" /n " & AddInInst.ProgId _
& " /p " & lngPID & " /t " & lngThreadID
Shell s
End If
....
end of code
Thanks
///M
Option Explicit
Private Declare Function Process32First Lib "kernel32" ( _
ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" ( _
ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "Kernel32.dll" _
(ByVal Handle As Long) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" _
(ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _
ByVal dwProcId As Long) As Long
Private Declare Function EnumProcesses Lib "psapi.dll" _
(ByRef lpidProcess As Long, ByVal cb As Long, _
ByRef cbNeeded As Long) As Long
Private Declare Function GetModuleFileNameExA Lib "psapi.dll" _
(ByVal hProcess As Long, ByVal hModule As Long, _
ByVal ModuleName As String, ByVal nSize As Long) As Long
Private Declare Function EnumProcessModules Lib "psapi.dll" _
(ByVal hProcess As Long, ByRef lphModule As Long, _
ByVal cb As Long, ByRef cbNeeded As Long) As Long
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" ( _
ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function GetVersionExA Lib "kernel32" _
(lpVersionInformation As OSVERSIONINFO) As Integer
Public Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long ' This process
th32DefaultHeapID As Long
th32ModuleID As Long ' Associated exe
cntThreads As Long
th32ParentProcessID As Long ' This process's parent process
pcPriClassBase As Long ' Base priority of process threads
dwFlags As Long
szExeFile As String * 260 ' MAX_PATH
End Type
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long '1 = Windows 95.
'2 = Windows NT
szCSDVersion As String * 128
End Type
Public Const PROCESS_QUERY_INFORMATION = 1024
Public Const PROCESS_VM_READ = 16
Public Const MAX_PATH = 260
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const SYNCHRONIZE = &H100000
'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Public Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Const TH32CS_SNAPPROCESS = &H2&
Public Const hNull = 0
Public m_lngPID As Long
Function StrZToStr(s As String) As String
On Error Resume Next
StrZToStr = Left$(s, Len(s) - 1)
End Function
Public Function getVersion() As Long
On Error Resume Next
Dim osinfo As OSVERSIONINFO
Dim retvalue As Integer
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
getVersion = osinfo.dwPlatformId
End Function
Public Function IsOutlookProcess() As Boolean
On Error Resume Next
Select Case getVersion()
Case 1 'Windows 98/ME
Dim f As Long, sname As String
Dim hSnap As Long, proc As PROCESSENTRY32
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If hSnap = hNull Then Exit Function
proc.dwSize = Len(proc)
' Iterate through the processes
f = Process32First(hSnap, proc)
Do While f
sname = StrZToStr(Trim(proc.szExeFile))
sname = Right(sname, Len(sname) - InStrRev(sname,
"\"))
If StrComp(sname, "outlook.exe", vbTextCompare) = 0
Then
If m_lngPID = proc.th32ProcessID Then
IsOutlookProcess = True
Exit Function
End If
End If
f = Process32Next(hSnap, proc)
Loop
Case 2 'Windows NT/2000/XP
Dim cb As Long
Dim cbNeeded As Long
Dim NumElements As Long
Dim ProcessIDs() As Long
Dim cbNeeded2 As Long
Dim NumElements2 As Long
Dim Modules(1 To 200) As Long
Dim lRet As Long
Dim ModuleName As String
Dim nSize As Long
Dim hProcess As Long
Dim i As Long
'Get the array containing the process id's for each process
object
cb = 8
cbNeeded = 96
Do While cb <= cbNeeded
cb = cb * 2
ReDim ProcessIDs(cb / 4) As Long
lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
Loop
NumElements = cbNeeded / 4
For i = 1 To NumElements
'Get a handle to the Process
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
Or PROCESS_VM_READ, 0, ProcessIDs(i))
'Got a Process handle
If hProcess <> 0 Then
'Get an array of the module handles for the specified
process
lRet = EnumProcessModules(hProcess, Modules(1), 200, _
cbNeeded2)
'If the Module Array is retrieved, Get the
ModuleFileName
If lRet <> 0 Then
ModuleName = Space(MAX_PATH)
nSize = 500
lRet = GetModuleFileNameExA(hProcess, Modules(1),
_
ModuleName, nSize)
ModuleName = StrZToStr(Trim(ModuleName))
ModuleName = Right(ModuleName, Len(ModuleName) -
InStrRev(ModuleName, "\"))
If LCase(ModuleName) = "outlook.exe" Then
If m_lngPID = ProcessIDs(i) Then
IsOutlookProcess = True
'Close the handle to the process
lRet = CloseHandle(hProcess)
Exit Function
End If
End If
End If
End If
'Close the handle to the process
lRet = CloseHandle(hProcess)
Next
End Select
End Function
Public Function IsAddInMonProcess() As Boolean
On Error Resume Next
Select Case getVersion()
Case 1 'Windows 98/ME
Dim f As Long, sname As String
Dim hSnap As Long, proc As PROCESSENTRY32
hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If hSnap = hNull Then Exit Function
proc.dwSize = Len(proc)
' Iterate through the processes
f = Process32First(hSnap, proc)
Do While f
sname = Trim(TrimNull(proc.szExeFile))
sname = Right(sname, Len(sname) - InStrRev(sname,
"\"))
If StrComp(sname, "addinmon.exe", vbTextCompare) = 0
Then
IsAddInMonProcess = True
Exit Function
End If
f = Process32Next(hSnap, proc)
Loop
Case 2 'Windows NT/2000/XP
Dim cb As Long
Dim cbNeeded As Long
Dim NumElements As Long
Dim ProcessIDs() As Long
Dim cbNeeded2 As Long
Dim NumElements2 As Long
Dim Modules(1 To 200) As Long
Dim lRet As Long
Dim ModuleName As String
Dim nSize As Long
Dim hProcess As Long
Dim i As Long
'Get the array containing the process id's for each process
object
cb = 8
cbNeeded = 96
Do While cb <= cbNeeded
cb = cb * 2
ReDim ProcessIDs(cb / 4) As Long
lRet = EnumProcesses(ProcessIDs(1), cb, cbNeeded)
Loop
NumElements = cbNeeded / 4
For i = 1 To NumElements
'Get a handle to the Process
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION _
Or PROCESS_VM_READ, 0, ProcessIDs(i))
'Got a Process handle
If hProcess <> 0 Then
'Get an array of the module handles for the specified
process
lRet = EnumProcessModules(hProcess, Modules(1), 200, _
cbNeeded2)
'If the Module Array is retrieved, Get the
ModuleFileName
If lRet <> 0 Then
ModuleName = Space(MAX_PATH)
nSize = 500
lRet = GetModuleFileNameExA(hProcess, Modules(1),
_
ModuleName, nSize)
ModuleName = Trim(TrimNull(ModuleName))
ModuleName = Right(ModuleName, Len(ModuleName) -
InStrRev(ModuleName, "\"))
If LCase(ModuleName) = "addinmon.exe" Then
IsAddInMonProcess = True
'Close the handle to the process
lRet = CloseHandle(hProcess)
Exit Function
End If
End If
End If
'Close the handle to the process
lRet = CloseHandle(hProcess)
Next
End Select
End Function
Private Function TrimNull(ByVal StrIn) As String
On Error Resume Next
TrimNull = Left$(StrIn, InStr(StrIn, vbNullChar) - 1)
End Function
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Lead Author, Beginning VB 6 Application Development, Wrox Press
Attachment Options
http://www.slovaktech.com/attachmentoptions.htm
Extended Reminders
http://www.slovaktech.com/extendedreminders.htm
"M" <mats.an...@cybernetics.se> wrote in message
news:ON$PEyQeCHA.4228@tkmsftngp08...
Thanks for pointing out this omission.
--
Randy Byrne, MVP - Outlook
http://www.microeye.com
Building Applications with Microsoft Outlook 2002 (MSPress - July 2001)
Building Applications with Microsoft Outlook 2000 (MSPress)
http://www.microeye.com/books
Micro Eye ZipOut 2002
http://www.microeye.com/zipout
"M" <mats.an...@cybernetics.se> wrote in message
news:ON$PEyQeCHA.4228@tkmsftngp08...