You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用C#获取Outlook2010及更高版本已登录账户的stream_autocomplete_0文件GUID

C# 获取Outlook 2010+已登录账户对应stream_autocomplete文件GUID实现方案

核心逻辑

stream_autocomplete_*文件存储于当前用户%APPDATA%\Microsoft\Outlook\RoamCache目录,文件名中包含的GUID与Outlook注册表中存储的账户唯一标识一一对应,只需通过读取注册表账户信息匹配本地文件即可拿到关联关系。

完整实现代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Win32;

public class OutlookAutoCompleteTool
{
    public class OutlookAccount
    {
        /// <summary>
        /// 账户显示名称/邮箱地址
        /// </summary>
        public string AccountDisplayName { get; set; }
        /// <summary>
        /// 账户对应GUID,即stream_autocomplete文件名中的GUID部分
        /// </summary>
        public string AccountGuid { get; set; }
        /// <summary>
        /// 对应stream_autocomplete文件的完整路径
        /// </summary>
        public string AutoCompleteFilePath { get; set; }
    }

    /// <summary>
    /// 获取所有已登录Outlook账户对应的自动完成文件GUID信息
    /// </summary>
    public static List<OutlookAccount> GetAccountAutoCompleteGuids()
    {
        var result = new List<OutlookAccount>();
        // Outlook默认配置文件注册表路径,自定义配置需修改末尾的"Outlook"为对应配置名
        const string outlookProfileRegPath = @"Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook";
        string roamCacheDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Microsoft\Outlook\RoamCache");

        if (!Directory.Exists(roamCacheDir)) return result;

        using (var profileRegKey = Registry.CurrentUser.OpenSubKey(outlookProfileRegPath))
        {
            if (profileRegKey == null) return result;

            foreach (var subKeyName in profileRegKey.GetSubKeyNames())
            {
                // 过滤非GUID格式的子键,仅保留账户标识项
                if (!Guid.TryParse(subKeyName, out _)) continue;

                using (var accountRegKey = profileRegKey.OpenSubKey(subKeyName))
                {
                    if (accountRegKey == null) continue;
                    // 读取账户显示名称
                    var nameBytes = accountRegKey.GetValue("001f6620") as byte[];
                    if (nameBytes == null) continue;
                    string displayName = System.Text.Encoding.Unicode.GetString(nameBytes).TrimEnd('\0');

                    // 匹配对应的stream_autocomplete文件
                    var matchedFiles = Directory.GetFiles(roamCacheDir, $"stream_autocomplete_{subKeyName}_*", SearchOption.TopDirectoryOnly);
                    if (matchedFiles.Length == 0) continue;

                    result.Add(new OutlookAccount
                    {
                        AccountDisplayName = displayName,
                        AccountGuid = subKeyName,
                        // 按修改时间排序取最新的文件
                        AutoCompleteFilePath = matchedFiles.OrderByDescending(f => new FileInfo(f).LastWriteTime).First()
                    });
                }
            }
        }
        return result;
    }

    // 调用测试
    public static void Main()
    {
        var accountList = GetAccountAutoCompleteGuids();
        foreach (var account in accountList)
        {
            Console.WriteLine($"账户:{account.AccountDisplayName}");
            Console.WriteLine($"对应GUID:{account.AccountGuid}");
            Console.WriteLine($"自动完成文件路径:{account.AutoCompleteFilePath}");
            Console.WriteLine("-----------------------------------");
        }
    }
}

适用说明

  • 支持Outlook 2010、2013、2016、2019、365全版本
  • 程序仅需当前用户权限即可运行,无需管理员权限
  • 若存在多个Outlook配置文件,修改注册表路径中末尾的配置文件名即可适配

内容的提问来源于stack exchange,提问作者deven

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 14:15:00