Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Start Outlook w/ Default Profile

Posted on 1998-06-10
7
Medium Priority
?
210 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
Technology Partners: 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 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

721 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