Solved

Start Outlook w/ Default Profile

Posted on 1998-06-10
7
188 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:sgroner
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:Sekans
Comment Utility
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
Comment Utility
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:sgroner
Comment Utility
Start it like the Shortcut Bar would

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:Cardo
Comment Utility
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:sgroner
Comment Utility
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
Comment Utility
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:sgroner
Comment Utility
Thanks for the help.  I will check it out and get back to you shortly.


0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now