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

管理员权限程序调用Process.Start()启动mmc.exe打开dhcpmgmt.msc时出现“引用了不存在的令牌”错误求助

解决管理员权限下启动mmc加载dhcpmgmt.msc时的Token错误问题

这个问题我之前碰到过,大概率是Windows文件系统重定向在搞鬼!尤其是当你的程序是32位进程、运行在64位Windows系统上的时候,很容易触发这个问题。

问题原因

当32位程序以管理员权限访问C:\Windows\system32目录时,Windows会自动将请求重定向到C:\Windows\SysWOW64(专门存放32位系统文件的目录)。而dhcpmgmt.msc通常只有64位版本,或者在SysWOW64中不存在对应的兼容版本,导致mmc无法找到正确的管理单元,进而抛出“An attempt was made to reference a token that does not exist”错误。而启动cmd没问题,是因为SysWOW64里有32位的cmd.exe可以正常运行。

解决方案

方案1:直接使用Sysnative路径访问64位系统文件

Windows提供了Sysnative虚拟目录,允许32位程序直接访问64位的system32目录,无需修改代码逻辑,只需要调整调用路径:

startProcess("C:\\Windows\\Sysnative\\mmc.exe", "C:\\Windows\\Sysnative\\dhcpmgmt.msc");

如果你的程序需要兼容32/64位架构,可以先判断系统和进程类型再选择路径:

string systemDir = Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess 
    ? "C:\\Windows\\Sysnative" 
    : "C:\\Windows\\system32";

startProcess(Path.Combine(systemDir, "mmc.exe"), Path.Combine(systemDir, "dhcpmgmt.msc"));

方案2:临时禁用文件系统重定向

通过P/Invoke调用Windows API,在启动进程前禁用重定向,启动完成后恢复:

using System.Runtime.InteropServices;
using System.Diagnostics;

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr);

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);

private static void startProcess(String fileName, String arguments) {
    IntPtr wow64Ptr = IntPtr.Zero;
    bool isRedirectionDisabled = false;

    try {
        // 仅在64位系统的32位进程中禁用重定向
        if (Environment.Is64BitOperatingSystem && !Environment.Is64BitProcess) {
            isRedirectionDisabled = Wow64DisableWow64FsRedirection(ref wow64Ptr);
        }

        Process proc = new Process();
        proc.StartInfo.FileName = fileName;
        proc.StartInfo.Arguments = arguments;
        // 禁用ShellExecute,避免权限传递问题
        proc.StartInfo.UseShellExecute = false;
        proc.Start();
    }
    finally {
        // 恢复文件系统重定向
        if (isRedirectionDisabled) {
            Wow64RevertWow64FsRedirection(wow64Ptr);
        }
    }
}

额外注意点

  • 确保你的管理员账户拥有DHCP管理单元的访问权限(默认管理员账户通常具备该权限,受限管理员可能需要调整权限设置)。
  • 如果你的程序本身是64位架构,直接使用原路径就能正常运行,不需要上述特殊处理。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 00:12:36