Solved

Start Outlook w/ Default Profile

Posted on 1998-06-10
7
194 Views
Last Modified: 2012-05-04
Using VB5 Code, how do I start MS Outlook with the users default profile.  Please provide code for points.

0
Comment
Question by:Steve Groner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:Sekans
ID: 1462993
I don't know much about MS Outlook, but if you're using Win95 or NT, this code should retrieve your default profile.


Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long


Dim dProfile As String
Dim keyHandle As Long
Dim dataType As Long
Dim dataSize As Long
dProfile = Space(255)
dataSize = Len(dProfile)
If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles", 0, KEY_READ, keyHandle)
Then
    If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\Microsoft\Windows Messaging Subsystem\Profiles", 0, KEY_READ, keyHandle) Then Exit Function
End If
If RegQueryValueEx(keyHandle, "DefaultProfile", 0, dataType, ByVal dProfile, dataSize) Then Exit Function
If RegCloseKey(keyHandle) Then Exit Function
dProfile = Left(dProfile, dataSize - 1)

Regards,
Sekans
0
 
LVL 1

Expert Comment

by:Cardo
ID: 1462994
Do you want to start outlook from your app and be able to send/receive mail into your app from outlook, or just start it much like the Office Shortcut bar would?
0
 
LVL 1

Author Comment

by:Steve Groner
ID: 1462995
Start it like the Shortcut Bar would

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Cardo
ID: 1462996
You could just use a Shell statement to load the exe, and as long as Outlook is configured not to prompt for a profile, this should take the user straight in.
0
 
LVL 1

Author Comment

by:Steve Groner
ID: 1462997
Ok, but how do I know where the file is.  I do not want to have to search the entire disk for it.  I thought there was an Registry Entry that stored the location.  Also I need to know when it closes.  Any more ideas.
0
 
LVL 1

Accepted Solution

by:
Cardo earned 50 total points
ID: 1462998
Put this into a small program with a button called Command1 and this should load outlook, and then freeze until outlook is closed.

Option Explicit

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const INFINITE = &HFFFFFFFF       '  Infinite timeout
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const SYNCHRONIZE = &H100000
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) 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 RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Private Sub Command1_Click()

Dim phnd As Long, pid As Long, sOTPath As String
Dim keyHandle As Long, lType As Long, lSize As Long

sOTPath = Space(255)
lSize = Len(sOTPath)

If RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE", 0, KEY_READ, keyHandle) Then
    MsgBox "Failed to obtain Outlook path from Registry"
    Exit Sub
End If
If RegQueryValueEx(keyHandle, "", 0, lType, ByVal sOTPath, lSize) Then
    MsgBox "Failed to obtain Outlook path from Registry"
    Exit Sub
End If
If RegCloseKey(keyHandle) Then
    MsgBox "Failed to obtain Outlook path from Registry"
    Exit Sub
End If
sOTPath = Left(sOTPath, lSize - 1)

pid = Shell(sOTPath, vbNormalFocus)
If pid <> 0 Then
    phnd = OpenProcess(SYNCHRONIZE, 0, pid)
    If phnd <> 0 Then
        Call WaitForSingleObject(phnd, INFINITE) 'this will return when closes
        Call CloseHandle(phnd)
    End If
Else
    MsgBox "Failed to load outlook.exe"
End If

End Sub

PS.  This is probably a little more involved than just easy!
0
 
LVL 1

Author Comment

by:Steve Groner
ID: 1462999
Thanks for the help.  I will check it out and get back to you shortly.


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question