Solved

Start Outlook w/ Default Profile

Posted on 1998-06-10
7
189 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
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:sgroner
ID: 1462995
Start it like the Shortcut Bar would

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

932 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