Software⏱️ 3 min read📅 2026-06-11

How to Fix error code 5 Error – query session command gives error code 5 even when AllowRemoteRPC is set to 1

Error code 5 occurs when Access is denied despite AllowRemoteRPC being set to 1.

Quick Answer: Check if the user account has sufficient permissions and try running the command as an administrator.

The 'Query Session' command is returning an error code 5, despite having AllowRemoteRPC set to 1, affecting Windows 10 Remote Desktop users. This issue can be frustrating for administrators trying to troubleshoot and manage remote sessions.

AllowRemoteRPC is a setting that enables remote access to the Terminal Server session. However, its value being set to 1 does not guarantee successful connection attempts. The error code 5 indicates an 'Access is denied' issue, which may be due to various reasons such as incorrect configuration or permissions.

⚠️ Common Causes

  • The primary reason for this error is that the AllowRemoteRPC setting only affects the Terminal Server session, but not all remote desktop connections. To resolve this issue, it's essential to understand that AllowRemoteRPC does not enable remote access to individual user sessions. Instead, it controls the Terminal Server session level. Therefore, if you're trying to connect to a specific user session, you may need to use alternative methods.
  • Another possible reason is that the remote desktop connection is being established using a different protocol or authentication method that bypasses the AllowRemoteRPC setting. In this case, you may need to investigate and adjust your remote desktop configuration to ensure compatibility with the Query Session command.

🛠️ Step-by-Step Verified Fixes

Enabling Terminal Server Session Configuration

  1. Step 1: Step 1: Open the Registry Editor and navigate to HKLM\SYSTEM\CurrentControlSet\Control\TerminalServer. Ensure that the AllowRemoteRPC value is set to 1.
  2. Step 2: Step 2: Restart the Remote Desktop Service or restart the computer for the changes to take effect.
  3. Step 3: Step 3: Verify that the Terminal Server session configuration is correct by running the 'Query Session' command again.

Using Alternative Methods to Connect to User Sessions

  1. Step 1: Step 1: Use the 'mstsc /v' command with the '-session' option to connect directly to a specific user session. For example, 'mstsc /v :'. This method bypasses the AllowRemoteRPC setting and allows you to connect to individual user sessions.
  2. Step 2: Step 2: Verify that the remote desktop connection is successful by checking the Event Viewer logs for any errors or warnings related to the user session.

🎯 Final Words

In summary, resolving the 'Query Session' command error code 5 requires understanding the limitations of the AllowRemoteRPC setting and using alternative methods to connect to individual user sessions. By following the steps outlined above, you should be able to troubleshoot and resolve this issue, ensuring successful remote desktop connections.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions