如何确定Outlook是否有任何联系人
我有一个VB.NET Windows应用程序,其中使用Outlook的联系人作为通讯簿来获取电子邮件地址列表.我希望它使用Outlook作为通讯簿,但是如果尚未设置Outlook邮箱或没有联系人,那么我根本不希望Outlook出现.我遇到的问题是,当我尝试访问Outlook时,就会出现Outlook启动向导,这是我不希望发生的.这是我的代码:
I have a VB.NET windows application in which I'm using Outlook's contacts as my address book to get a list of email addresses. I'd like it to use Outlook as the address book, but if an Outlook mailbox has not been set up or there are no contacts then I don't want Outlook to come up at all. The problem that I'm having is as soon as I try to access Outlook the Outlook Startup Wizard comes up, which I don't want to happen. Here is my code:
Dim ao As Outlook.Application
Dim ons As Outlook.NameSpace
Dim Contacts As Outlook.Items
ao = New Outlook.Application
' The Outlook Startup Wizard comes up on this line of code.
ons = ao.GetNamespace("MAPI")
您可以检查以下注册表项以查看是否已配置Outlook:
You can check the following registry key to see if Outlook has been configured yet:
"HKEY_CURRENT_USER \ Software \ Microsoft \ Windows NT \ CurrentVersion \ Windows \ Messaging Subsystem \ Profiles"
"HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Messaging Subsystem\Profiles"
以下代码示例对此进行了演示:
The following code sample demonstrates this:
Imports Microsoft.Win32
Module Module1
Sub Main()
Console.WriteLine("Outlook Profile Setup?:" + OutlookProfileExists().ToString())
Console.ReadLine()
End Sub
Public Function OutlookProfileExists() As Boolean
Dim rk As RegistryKey = Registry.CurrentUser
Dim sk = rk.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles")
Return sk.SubKeyCount > 0
End Function
End Module
假设它已配置,然后像往常一样启动并检查联系人列表.无论如何,我找不到启动该联系人列表就无法读取它,但是至少您可以验证它是否已配置.
Assuming it's configured then launch like normal and check the contact list. I can't find anyway to read the contact list without launching it, but at least you can verify if it's configured.