WMI 创建网站 (C#) 的错误 CreateServer 绑定

Error CreateServer Binding for WMI Create website (C#)

请帮帮我!

我已经审阅了大约 100 个源页面。

我就是做不到。

我工作2天。

我的最后一点是创建绑定。

我遇到 "Access Denied" 错误。

[TR] 我查看了大约 100 个源页面。

我做不到。

苦苦挣扎了2天

我的最后一点是创建绑定。

我收到错误

"Access Denied".

错误;

public void Creator()
{

    string hostName = "BuBirSitedir";
    string domainName = "www.bubirsitedir.com";

    ConnectionOptions options = new ConnectionOptions();
    options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
    options.Authentication = AuthenticationLevel.Connect;
    options.EnablePrivileges = true;
    options.Impersonation = ImpersonationLevel.Default;

    ManagementClass classInstance = new ManagementClass("root\WebAdministration", "Site", null);

    ManagementScope scope = new ManagementScope(string.Format(@"\{0}\root\MicrosoftIISV2", "DESKTOP-MGA1F3C"), options);
    scope.Connect();

    ManagementBaseObject[] serverBindings = new ManagementBaseObject[3];
    serverBindings[0] = CreateServerBinding(scope, string.Format("{0}", hostName, domainName), "127.0.0.1", 40804);
    serverBindings[1] = CreateServerBinding(scope, string.Format("30603", hostName, domainName), "127.0.0.1", 30603);
    serverBindings[2] = CreateServerBinding(scope, string.Format("127.0.0.1", hostName, domainName), "127.0.0.1", 20402);
}

private static ManagementObject CreateServerBinding(ManagementScope scope, string hostName, string ip, int port)
{
    ManagementClass mc = new ManagementClass(scope, new ManagementPath("ServerBinding"), null);
    ManagementObject mco = mc.CreateInstance();
    mco.Properties["Hostname"].Value = hostName;
    mco.Properties["IP"].Value = ip;
    mco.Properties["Port"].Value = port;
    mco.Put();
    return mco;
}

我解决了问题。

我的电脑(右键单击)> 管理 > 计算机管理(本地)> 服务和应用程序 > WMI 控制(右键单击)> 安全(选项卡)> 列表项 select 并单击安全按钮 > Select 用户 > 所有允许 > 确定

未列出用户。单击高级按钮。输入 "everyone" 并输入。

enter image description here