以编程方式配置Outlook的地址列表选项

时间:2016-08-23 10:00:06

标签: powershell outlook registry programmatically-created

我需要以编程方式(理想情况下通过PowerShell)配置Outlook设置选项:

  1. “发送电子邮件时,请按此顺序检查地址列表:”至“以联系人文件夹开头”。
  2. “打开地址簿时,首先显示此地址列表:”至“Outlook地址簿”。
  3. 这个问题已经证明是特别难以捉摸的,而且我在很长时间内一直在研究这个问题,所以我的综合发现可能看起来有点混乱。

    选项#1

    如果我没记错,以下PowerShell命令已成功配置选项:

    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "000b3d1c" -PropertyType "Binary" -Value 0x00,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "00033d1b" -PropertyType "Binary" -Value 0x02,0x00,0x00,0x00 -Force;
    

    选项#2

    将注册表项HKCU\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>导出到REG文件,重新创建邮件配置文件,导入REG文件以及打开Outlook显示选项已根据需要进行设置。所以,它可以通过注册表完成。

    进程监视器,配置为使用筛选器Process Name is OUTLOOK.EXE IncludeOperation is RegSetValue Include监视注册表操作,始终输出略有不同的结果,但结果一致:

      

    15:48:56.9983649 OUTLOOK.EXE 531284 RegSetValue HKCU \ Software \ Microsoft \ Office \ 15.0 \ Outlook \ Profiles \ Student \ 9207f3e0a3b11019908b08002b2a56c2 \ 01023d06 SUCCESS类型:REG_BINARY,长度:44,数据:00 00 00 00 FE 42 AA 0A 18 C7 1A 10 E8 85 0B 65

         

    15:48:56.9991115 OUTLOOK.EXE 531284 RegSetValue HKCU \ Software \ Microsoft \ Office \ 15.0 \ Outlook \ Profiles \ Student \ 0a0d020000000000c000000000000046 \ 000b3d1c SUCCESS类型:REG_BINARY,长度:2,数据:00 00

         

    15:48:56.9996963 OUTLOOK.EXE 531284 RegSetValue HKCU \ Software \ Microsoft \ Office \ 15.0 \ Outlook \ Profiles \ Student \ 0a0d020000000000c000000000000046 \ 00033d1b SUCCESS类型:REG_BINARY,长度:4,数据:02 00 00 00

         

    15:48:57.0052360 OUTLOOK.EXE 531284 RegSetValue HKCU \ Software \ Microsoft \ Office \ 15.0 \ Outlook \ Profiles \ Student \ 4ae4e14443f96d4982c25a0b9340e560 \ 000b048b SUCCESS类型:REG_BINARY,长度:2,数据:01 00

         

    15:49:03.0985853 OUTLOOK.EXE 531284 RegSetValue HKCU \ Software \ Microsoft \ Office \ 15.0 \ Outlook \ Profiles \ Student \ 0a0d020000000000c000000000000046 \ 1102039b SUCCESS类型:REG_BINARY,长度:308,数据:01 00 00 00 1D 01 00 00 00 00 00 00 14 00 00 00

         

    15:49:03.0990695 OUTLOOK.EXE 531284 RegSetValue HKCU \ Software \ Microsoft \ Office \ 15.0 \ Outlook \ Profiles \ Student \ 0a0d020000000000c000000000000046 \ 000b0415 SUCCESS类型:REG_BINARY,长度:2,数据:00 00

    但是,以下PowerShell命令未成功配置选项:

    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "000b046b" -PropertyType "Binary" -Value 0x01,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\9207f3e0a3b11019908b08002b2a56c2\" -Name "01023d06" -PropertyType "Binary" -Value 0x00,0x00,0x00,0x00,0xFE,0x42,0xAA,0x0A,0x18,0xC7,0x1A,0x10,0xE8,0x85,0x0B,0x65 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "000b3d1c" -PropertyType "Binary" -Value 0x00,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "00033d1b" -PropertyType "Binary" -Value 0x02,0x00,0x00,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "000b0340" -PropertyType "Binary" -Value 0x01,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\9207f3e0a3b11019908b08002b2a56c2\" -Name "11023d05" -PropertyType "Binary" -Value 0x02,0x00,0x00,0x00,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x00,0x00,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\b9e1c8a47102f24688ede3f23cbc5224\" -Name "0102663b" -PropertyType "Binary" -Value 0x0F,0x00,0x01,0x00,0x8C,0x01,0x21,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "1102039b" -PropertyType "Binary" -Value 0x01,0x00,0x00,0x00,0x1D,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00 -Force;
    New-ItemProperty -Path "HKCU:\Software\Microsoft\Office\<Outlook version>\Outlook\Profiles\<mail profile name>\0a0d020000000000c000000000000046\" -Name "000b0415" -PropertyType "Binary" -Value 0x00,0x00 -Force;
    

    Set Outlook's 'show this address list first' option表明这可以通过使用ComObjects来完成,但测试显示Outlook将该活动检测为恶意,并提示需要手动干预的安全警告,这显然是有问题的,因为它不是100%程序化。

    https://social.technet.microsoft.com/Forums/exchange/en-US/85a392d4-fc85-43c5-9c02-c07ec86e2ade/default-address-list?forum=exchangesvrclientslegacyhttps://social.technet.microsoft.com/Forums/office/en-US/6bb9b40f-b794-41ce-93b4-711e77c53607/gal-default-adress-book-gpo表示注册表项*\<mail profile name>\9207f3e0a3b11019908b08002b2a56c2 - &gt;值01023d06是由Process Monitor检测到的,但如上所述,它在我的测试中没有用。

3 个答案:

答案 0 :(得分:1)

在扩展MAPI(C ++或Delphi)中使用IAddrBook.SetDefaultDirIAddrBook.SetSearchPath设置该选项。 Outlook对象模型不会公开该功能。如果使用Redemption是一个选项(任何语言),它会公开RDOAddressBookDefaultAddressListSearchPath  属性。

答案 1 :(得分:0)

我写了这个PS脚本来改变“打开地址簿时,首先显示这个地址列表:”

## Script for setting default address book view in Outlook for CU
#
# Input (const):
#   <$cAddrList> GUID for needed address list
#   Dump REG_BINARY value of '01023d06' from key
#   HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Profiles\Outlook\9207f3e0a3b11019908b08002b2a56c2\
#
# Version 1.2
# (c)kMit 2017
#

#AddressList string - 'BigBoxList'
$cAddrList = 'fe000000000000000000000000000000000000ff01000000000100002f677569643d393536324239433038413232374234454236313831443644364236323635353100'

#Outlook profiles registry path
$cMSOProf = '\Software\Microsoft\Office\15.0\Outlook\Profiles\'
$cMSOPFil = '*Outlook'
$cMSORK01 = '\9207f3e0a3b11019908b08002b2a56c2'
$cMSORSrc = '11023d05'
$cMSORTrg = '01023d06'
$cMSORK02 = '\0a0d020000000000c000000000000046'
$cMSORBFM = '000b3d1c'
#\''

#Get list of Outlook profiles
$pList = (Get-ChildItem -Path HKCU:$cMSOProf -ErrorAction SilentlyContinue)

#Select profile - profile name doesn't matter if it's single, or the first one that matches $cMSOPFil
if($pList) {
    if($pList.GetType().BaseType.Name -eq 'Array') {
        $pTarg = ($pList | ? {$_.Name -like $cMSOPFil})[0]
    } else {
        $pTarg = $pList
    }
}

#Change profile
if($pTarg -and (Get-ChildItem HKCU:$pTarg -ErrorAction SilentlyContinue)) {
    $rKey = 'HKCU:'+$pTarg.Name.Substring(17)

    try {
        $is = (Get-ItemProperty -Path ($rKey+$cMSORK01)).$cMSORSrc

        #Make value and copy header
        $it = @(($cAddrList -split '([a-f0-9]{2})') | ForEach-Object {if($_) {[System.Convert]::toByte($_,16)}})
        for($i=0;$i -lt 20;$i++) {$it[$i] = $is[$i+20]}

        #Write result
        Set-ItemProperty -Path ($rKey+$cMSORK01) -Name $cMSORTrg -Type Binary -Value ([byte[]]($it))
        #Disable auto-select ('Choose automatically')
        Set-ItemProperty -Path ($rKey+$cMSORK02) -Name $cMSORBFM -Type Binary -Value ([byte[]](0,0))
    }
    catch {
        break
    }
}

答案 2 :(得分:0)

部分答案,解决如何更改OP请求的第一个设置。

设置发送电子邮件时,按此顺序检查地址列表可以通过修改以下注册表来更改:

密钥: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\[OutlookVersion]\Outlook\Profiles\[OutlookProfileName]\0a0d020000000000c000000000000046

  • [OutlookVersion] 是Outlook的版本(例如15.0
  • [OutlookProfileName] 是用户的Outlook个人资料名称(例如Outlook)。

值名称: 00033d1b(类型:REG_BINARY)

数据:

  • 01 00 00 00启用以全局地址列表开头
  • 02 00 00 00启用以联系人文件夹开头

更改设置的PowerShell

假设Outlook 15.0和个人资料名称为&#34; Outlook&#34;:

启用以全局地址列表开头

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles\Outlook\0a0d020000000000c000000000000046\" -Name 00033d1b -Value ([byte[]](0x01,0x00,0x00,0x00))

启用以联系人文件夹开头

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Office\15.0\Outlook\Profiles\Outlook\0a0d020000000000c000000000000046\" -Name 00033d1b -Value ([byte[]](0x02,0x00,0x00,0x00))

备注:

  • 这可以在Outlook打开时更改;变更立即生效。
  • 使用Set-ItemProperty假设注册表中已存在值00033d1b
  • 感谢此SO answer解释如何使用[byte[]]语法。
  • 感谢此SO question提供了寻找答案的起点。