因 DHCP 客户端服务已禁用而无法通过 RDP 连接到 Azure 虚拟机Cannot RDP to Azure Virtual Machines because the DHCP Client service is disabled

本文介绍了在 Azure Windows 虚拟机 (VM) 中禁用 DHCP 客户端服务后无法通过远程桌面连接到该 VM 的问题。This article describes a problem in which you cannot remote desktop to Azure Windows Virtual Machines (VMs) after the DHCP Client service is disabled in the VM.

症状Symptoms

无法在 Azure 中与 VM 建立 RDP 连接,因为 DHCP 客户端服务在 VM 中被禁用。You cannot make an RDP connection a VM in Azure because the DHCP Client service is disabled in the VM. 在 Azure 门户中的“启动诊断”中检查屏幕截图时,你看到 VM 正常启动并且在登录屏幕中等待凭据。When you check the screenshot in the Boot diagnostics in the Azure portal, you see the VM boots normally and waits for credentials in the login screen. 在使用事件查看器远程查看 VM 中的事件日志时,You remotely view the event logs in the VM by using Event Viewer. 发现 DHCP 客户端服务未启动或无法启动。You see that the DHCP Client Service isn't started or fails to start. 下面是示例日志:The following a sample log:

日志名称:系统Log Name: System
:服务控制管理器Source: Service Control Manager
日期:2015/12/16 11:19:36 AMDate: 12/16/2015 11:19:36 AM
事件 ID:7022Event ID: 7022
任务类别:无Task Category: None
级别:错误Level: Error
关键字:经典Keywords: Classic
用户:不适用User: N/A
计算机:myvm.cosotos.comComputer: myvm.cosotos.com
说明:DHCP 客户端服务在启动时挂起。Description: The DHCP Client service hung on starting.

对于资源管理器 VM,可使用串行访问控制台功能,通过以下命令查询事件日志 7022:For Resource Manager VMs, you can use Serial Access Console feature to query for the event logs 7022 using the following command:

wevtutil qe system /c:1 /f:text /q:"Event[System[Provider[@Name='Service Control Manager'] and EventID=7022 and TimeCreated[timediff(@SystemTime) <= 86400000]]]" | more

对于经典 VM,你需要在“脱机”模式下工作,并手动收集日志。For Classic VMs, you will need to work in OFFLINE mode and collect the logs manually.

原因Cause

DHCP 客户端服务未在 VM 上运行。The DHCP Client Service is not running on the VM.

Note

本文仅适用于 DHCP 客户端服务,而不适用于 DHCP 服务器。This article applies only for the DHCP Client service and not DHCP Server.

解决方案Solution

在执行这些步骤之前,请创建受影响 VM 的 OS 磁盘的快照作为备份。Before you follow these steps, take a snapshot of the OS disk of the affected VM as a backup. 有关详细信息,请参阅拍摄磁盘快照For more information, see Snapshot a disk.

若要解决此问题,请为 VM 重置网络接口To resolve this problem, reset network interface for the VM.

修复 VM 脱机Repair the VM offline

将 OS 磁盘附加到恢复 VMAttach the OS disk to a recovery VM

  1. 将 OS 磁盘附加到恢复 VMAttach the OS disk to a recovery VM.

  2. 开始与恢复 VM 建立远程桌面连接。Start a Remote Desktop connection to the recovery VM. 确保附加的磁盘在磁盘管理控制台中标记为“联机”。 Make sure that the attached disk is flagged as Online in the Disk Management console. 请注意分配给附加的 OS 磁盘的驱动器号。Note the drive letter that's assigned to the attached OS disk.

  3. 打开权限提升的命令提示符实例(“以管理员身份运行”)。 Open an elevated command prompt instance (Run as administrator). 然后运行以下脚本。Then run the following script. 此脚本假设分配给附加的 OS 磁盘的驱动器号为 F。使用 VM 中的值适当地替换该字母。This script assumes that the drive letter that's assigned to the attached OS disk is F. Replace the letter as appropriate with the value in your VM.

    reg load HKLM\BROKENSYSTEM F:\windows\system32\config\SYSTEM
    
    REM Set default values back on the broken service
    reg add "HKLM\BROKENSYSTEM\ControlSet001\services\DHCP" /v start /t REG_DWORD /d 2 /f
    reg add "HKLM\BROKENSYSTEM\ControlSet001\services\DHCP" /v ObjectName /t REG_SZ /d "NT Authority\LocalService" /f
    reg add "HKLM\BROKENSYSTEM\ControlSet001\services\DHCP" /v type /t REG_DWORD /d 16 /f
    reg add "HKLM\BROKENSYSTEM\ControlSet002\services\DHCP" /v start /t REG_DWORD /d 2 /f
    reg add "HKLM\BROKENSYSTEM\ControlSet002\services\DHCP" /v ObjectName /t REG_SZ /d "NT Authority\LocalService" /f
    reg add "HKLM\BROKENSYSTEM\ControlSet002\services\DHCP" /v type /t REG_DWORD /d 16 /f
    
    reg unload HKLM\BROKENSYSTEM
    
  4. 分离 OS 磁盘并重新创建 VMDetach the OS disk and recreate the VM. 然后检查是否解决了问题。Then check whether the problem is resolved.

后续步骤Next steps

如果仍需帮助,请联系支持人员以快速解决问题。If you still need help, contact support to get your problem resolved.