【问题标题】:SetComputerNameEX returns success but computer name not changed upon restartSetComputerNameEX 返回成功,但重新启动时计算机名称未更改
【发布时间】:2018-07-08 10:53:57
【问题描述】:

我正在尝试使用SetComputerNameEx() 更改域计算机的计算机名称。该函数返回成功,但是当我重新启动计算机时,它仍然具有旧的计算机名称。 SetComputerNameEx() 非常适用于非域机器我只在域计算机上遇到这个问题。我错过了什么吗?

编辑:我正在使用以下代码。

BOOL ChangeCompName(CString csCompName)
{
    if( !SetComputerNameEx(ComputerNamePhysicalDnsHostname,csCompName.GetBuffer()))
    {
        _tprintf(L"Failed to set Physical DNS name %d\n",GetLastError());
        return FALSE;
    }
    else
    {
        _tprintf(L"Computer name change Success\n");
    }

    if( !SetComputerNameEx(ComputerNamePhysicalNetBIOS,csCompName.GetBuffer()))
    {
        _tprintf(L"Failed to set Physical NetBios name %d\n",GetLastError());
        return FALSE;
    }
    else
    {
        _tprintf(L"Computer name change Success\n");
    }

    return TRUE;
}
int main()
{
    if(!ChangeCompName(L"NewCompName"))
    {
        _tprintf(L"Failed to change Name.\n");
        return 1;
    }
    else
    {
        _tprintf(L"Computer name change.\n");
    }
     return 0;
}

我尝试使用管理员和系统权限运行代码。每次我运行代码时,它都会返回成功,但不会更改计算机名称。奇怪的是,这段代码对工作组计算机非常有效,而对域计算机却不起作用。

【问题讨论】:

  • 您缺少的一件事是minimal reproducible example。据我们所知,您可以重新设置旧名称...我们无法帮助您修复我们不知道的代码。
  • 进程必须有管理员权限。计算机必须是本地计算机。
  • 我已经添加了供您参考的代码

标签: c++ windows msdn computer-name


【解决方案1】:

我想出了如何对域机器进行计算机重命名。如果有人需要,这是解决方案。

不要调用SetComputerNameEx(),只需使用带有域管理员凭据的NetGetJoinInformation()。这将在域和本地重命名计算机。

【讨论】:

    猜你喜欢
    • 2014-03-07
    • 2020-10-06
    • 1970-01-01
    • 2016-10-26
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 2017-12-14
    • 2013-04-19
    相关资源
    最近更新 更多