Fix: “Cannot Connect to the Virtual Machine” Error in Windows

You will usually come across an error where you are unable to connect to the virtual machine in Hyper-V Manager. This is a common error that occurs due to the selection of the “Do not store my credentials” radio button. This causes the Virtual machine to pass the credentials of the account logged in to Windows in place of the ones used for authenticating to the Self-Service Portal.

Cannot connect to Hyper-V virtual machine
Cannot connect to Hyper-V virtual machine

In this guide, we will explain the method to prevent the issue where you cannot connect to the Virtual Machine.

Workaround: Restart the Virtual Machine

Before making any changes to your system, you must make sure that you have re-started the Virtual Machine manually.

  1. Right-click on the Virtual Machine.
  2. Select the “Turn off” option on the context menu.
    Turning off the virtual machine
    Turning off the virtual machine
  3. Restart the Virtual Machine after a while.

1. Turn on Store my credentials

One of the major reasons why you are facing this error is due to the credentials of User 1 (account logged in to Windows) are being passed instead of User 2 (authenticate to the SSP). By default, the “Do not store my credentials” is selected which causes this error. Therefore, you must manually select the radio button “Store my credentials” on the SSP login page to pass the credentials through User 2. 

2. Turn off NUMA Spanning

NUMA Spanning is a setting in the Virtual Machine Manager that allows you to run multiple virtual machines simultaneously. Additionally, it provides extra memory to the virtual machine than the one available on the single NUMA node. However, this setting causes performance issues when connecting to the Virtual Machine. Below are the instructions for turning off the NUMA Spanning setting in the Hyper -V Manager.

  1. Click on the Hyper-V Manager Action on the left panel.
  2. Right-click on your PC name and select “Hyper-V Settings.”
    Opening Hyper V settings
    Opening Hyper V settings
  3. Under “Server”, click “NUMA Spanning” and uncheck the “Allow virtual machines to span physical NUMA nodes” box.
  4. Confirm the action with Apply and OK. 
    Turning off NUMA spanning
    Turning off NUMA spanning
  5. Now, you can restart the Hyper-V Virtual Machine Management Service and connect to the virtual machine.

3. Uninstall third-party VPN software

Although VPNs are a safe way to keep your data Unencrypted and secure, they are known to cause connection issues with the Virtual Machine you create on Hyper-V. Therefore, it is best to run a VPN directly within the virtual machine and remove any third-party VPN software from your system:

  1.  Press Win + I to open the Windows Settings.
  2. Navigate to Apps > Apps and features.
  3. Locate the VPN software on your system.
  4. Click on it to expand it and select “Uninstall”

    Uninstalling VPN software
    Uninstalling VPN software
In most cases, Windows fails to recognize VPN software as its application. In this case, you can manually uninstall it from the control panel.
  1. Open the Run command with Win +R keys.
  2. Type “control panel” and click OK.
     
    Opening the control panel
    Opening the control panel
  3. Click on the View by option and select “Large icons”
    Settings Icons at Large Font Size
    Settings Icons at Large Font Size
  4. Open Program and Features.
    Opening program and features
    Opening program and features
  5. Select the installed VPN software and click “Uninstall”
    Uninstalling VPN
    Uninstalling VPN

4. Uncheck the override system setting

Code flow guard is a feature in Windows that helps minimize memory corruption. However, it can also be a cause that prevents you from connecting to the Virtual Machine in Hyper-V. Therefore, you must turn it off. 

  1. Open the Windows Settings by pressing the Win + I keys.
  2. Navigate to Update and Security > Windows Security > App and browse control.
  3. Open the Exploit protection settings under “Exploit protection”
    Exploit protection settings
    Exploit protection settings
  4. Click on the Program settings and expand the following path:
    C:\WINDOWS\System32\vmcompute.exe
  5. Click Edit and find Code flow guard (CFG).
  6. Uncheck the Override system settings option.
  7. Open the Windows start menu and type “Powershell”
  8. Run Windows PowerShell as an administrator.
    Running powershell as an administrator
    Running PowerShell as an administrator
  9. Lastly, type the following command to start vmcompute:
    net start vmcompute
    vmcompute
    vmcompute

5. Restart each Hyper – V related services

An error in the Hyper-V services can be causing this connection error. Therefore, you must restart the Hyper-V-related services running in the background. You can do that with the instructions below:

  1. Open the Windows start menu with the Win key.
  2. Type “cmd” and run it as an administrator.
  3. Type the following commands and press Enter to restart each Hyper-V service:
    sc config vmickvpexchange start= demand
    sc config vmicguestinterface start= demand
    sc config vmicguestshutdown start= demand
    sc config vmicheartbeat start= demand
    sc config vmicvmsession start= demand
    sc config vmicrdv start= demand
    sc config vmicvss start= demand

6. Remove manual DNS entry

Having a manual DNS Entry saved in your Host file is also a reason that prevents you from connecting to the virtual machine. Therefore, you must check your host file and remove any manual DNS entries such as “rhino.acme.com” present there. You can do that with the steps listed below:

Note: Before making changes to the host file, you must make a backup copy in case your data gets lost.
  1. Press Win + E to open the file explorer.
  2. Paste the following path into the file explorer and press Enter. 
    C:\Windows\System32\drivers\etc\hosts 
  3. Select Notepad and click OK to open your host file.
    Opening host file in notepad
    Opening host file in notepad
  4. Remove the Manual DNS Entry called 102.54.94.97 rhino.acme.com with the Delete button.
    DNS Entry
    DNS Entry
  5. Save the Notepad file and relaunch the Hyper-V Manager.  
    Saving host file
    Saving host file

7. Disable the Cryptographic services 

Cryptographic services are used for encrypting and decrypting the available data and information stored on the storage devices upon accessing them. However, when connecting to the Virtual Machine, this service will interfere and prevent the connection from being made. Therefore, you must follow the instructions below to disable this service:

Warning: This method will cause any service to stop that depends on Cryptographic services.
  1. Open the Run command with the Win + R keys.
  2. Type “services.msc” and click OK to open Windows services.
    Opening Windows Services
    Opening Windows Services
  3. Right-click on Cryptographic services and open its properties.
    Opening cryptographic services properties
    Opening cryptographic services properties
  4. Change the Startup type to “Disabled.”
  5. Click on Apply and OK.

    Disabling the service
    Disabling the service

8. Change the default Windows port number

Windows has a default port number for the Hyper-V and Virtual Machine connectivity. When Windows fails to communicate with that port number, it fails to connect to the Virtual Machine. Changing this port number is known to fix connectivity errors. Therefore, you can change your default port number with the following instructions:

Turning off the virtual machine

  1. Right-click on the Virtual Machine.
  2. Select the “Turn off” option on the context menu.
    Turning off the virtual machine
    Turning off the virtual machine

Checking port number

  1. Open the run command with the Win +R keys.
  2. Type “regedit” and click OK to open the registry editor.
    Opening registry editor
    Opening registry editor
  3.  Navigate to the following path:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization
  4. Now, check the Listener port number on the right pane.
    Verifying listener port number
    Verifying listener port number

Verifying port number connection

  1. Open the Windows start menu with the Win key.
  2. Type “cmd” and run it as an administrator.
  3. Type the following command and press Enter
    netstat -ano | find "2179"
    Verifying port connection
    Verifying port connection
  4. The command fails to run which indicates that Windows has failed to connect to the Port.

Changing Port number

  1. Minimize the command prompt and return to the Registry Editor.
  2. Right-click on the Listener Port Registry key and select modify.

    Modifying the registry key
    Modifying the registry key
  3. Change the value to “21791” and select the Decimal radio button.
  4. Click OK to apply the changes.
    Changing value data
    Changing value data

Restarting the service

  1. Open the Windows start menu and type “PowerShell.”
  2. Run “Windows Powershell” as an administrator.
  3. Type the following commands to restart the virtual machine services:
    stop-service vmms
    start-service vmms
    Restarting Virtual machine service
    Restarting the Virtual machine service
  4. Open the minimized command prompt (as an administrator)
  5. Type the following command and press Enter
    netstat -ano | find "21791"

    Changing stat of the port Changing the state of the port

  6. When both TCPs are “LISTENING”, you can launch the Virtual Machine.
ABOUT THE AUTHOR

Muhammad Zubyan


Muhammad Zubyan is a certified Google IT Support Professional with over 7 years of extensive experience. He has worked on more than 1500 computers, gaining valuable insights that enable him to detect and troubleshoot any complicated root cause of Windows-related issues and errors. In addition to managing Appuals as a Senior Editor, he is currently developing his own Game Optimization program that caters to both gamers and casual users alike.