Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Start Outlook w/ Default Profile

Posted on 1998-06-10
7
Medium Priority
?
215 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
  • 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
Industry Leaders: 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Suggested Courses

926 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