Windows Server 2022: RDP Session

Abstract: Resolve Java application restarts on RDP session closure by running the app as a Windows Service or adjusting scheduled task settings.

Created: 2026-09-12 by

When a Java application restarts upon closing an RDP session on Windows Server 2022, it is typically because the process is launched via a user profile startup script or scheduled task that lacks proper session isolation. To resolve this, you must configure the application to run as a persistent service rather than a foreground process tied to the interactive desktop.

Understanding the Root Cause

The behavior described occurs because the Java application is likely configured to start automatically when any user logs into the server. In Windows Server environments, applications placed in the Startup folder or registered in the Run registry keys for all users will execute whenever a new session begins. When you close the RDP window, the session ends, but if the application was started by a trigger that persists beyond the session (such as a service or a misconfigured scheduled task), it may appear to restart or behave erratically. This issue is distinct from standard client-side disconnections. On Windows Server 2022, the Remote Desktop Services (RDS) architecture handles multiple sessions differently than consumer versions of Windows. If your Java application relies on the interactive desktop environment, closing the session terminates the associated processes. However, if the application is set to restart due to a dependency or a watchdog script, it will relaunch immediately. This often happens when administrators use Group Policy Objects (GPOs) to enforce application deployment without considering session state management. For more information on securing your RDP connections against unauthorized access during these transitions, see How to Restrict RDP and VPN Users/Connections on Windows Server 2022.

Solution 1: Run as a Windows Service

The most robust solution is to decouple the Java application from the user session entirely by running it as a Windows Service. Services run in Session 0, which is isolated from interactive user sessions. This ensures the application continues to operate regardless of whether any user is logged in via RDP. To implement this, you should use a wrapper tool such as WinSW (Windows Service Wrapper) or NSSM (Non-Sucking Service Manager). These tools allow you to register a standard executable or Java JAR file as a native Windows Service. 1. Download the chosen wrapper tool and place it in a secure directory, such as C:\Program Files\JavaService. 2. Create a configuration file (e.g., service.xml) that defines the Java executable path, classpath, and JVM arguments. 3. Install the service using the command line: nssm install MyJavaApp. 4. Set the startup type to "Automatic" in the Services console (services.msc). 5. Restart the service to ensure it launches independently of user logins. By moving the application to Session 0, closing your RDP session will no longer affect its lifecycle. The application will remain active in the background, providing consistent availability for other clients or internal processes.

Solution 2: Adjust Scheduled Task Settings

If running as a service is not feasible due to specific UI requirements, you can adjust the Scheduled Task settings to prevent interference with RDP sessions. Many administrators use Scheduled Tasks to launch applications at startup, but default settings often tie them to the "Log on User" context. Open the Task Scheduler and locate the task responsible for launching the Java application. Right-click the task and select Properties. Navigate to the General tab and ensure that "Run whether user is logged on or not" is selected. Then, go to the Conditions tab and uncheck "Start the task only if the computer is on AC power" if applicable, though this is less relevant for servers. Crucially, check the Settings tab. Ensure that "If the task fails, restart every" is set appropriately, but verify that the task does not have a condition requiring an interactive session. You may also need to modify the "Run as" account to use a dedicated service account rather than the interactive user account. This prevents the task from being terminated when the specific user's RDP session closes.

Solution 3: Configure Group Policy for Session Disconnect

Windows Server 2022 allows administrators to define what happens when an RDP session is disconnected versus closed. By default, some configurations may terminate applications upon disconnect. You can change this behavior via Group Policy. Navigate to Computer Configuration > Policies > Administrative Templates > Windows Components > Remote Desktop Services > Remote Desktop Session Host > Session Time Limits. Here, you can configure policies that keep sessions alive even when disconnected. Additionally, check Remote Desktop Session Host > Connections for settings related to "Restrict remote desktop services users to a single Remote Desktop Services session." Ensuring that sessions are preserved rather than killed can help maintain application state. While this approach helps preserve the session itself, it does not guarantee the application won't restart if the session is explicitly ended. Therefore, combining this with the Service or Scheduled Task methods provides the best stability. For broader context on managing RDP connectivity issues, refer to RDP Won't Connect with Public IP Despite Local Network Port Being Open.

Verifying the Fix

After applying one of the above solutions, test the configuration thoroughly. Log in via RDP, launch the application, and then disconnect the session (using the X button or minimizing the RDP window). Monitor the Application Event Log and the System Event Log for any errors related to the Java process. Use the Resource Monitor or Task Manager to verify that the process remains active under the correct user context (System for services, or the designated service account for tasks). If the application still exhibits unexpected behavior, review the JVM logs for exit codes. A clean shutdown indicates the application itself is handling the session closure correctly, while abnormal termination codes suggest external interference from Windows session management policies.

Frequently Asked Questions

Why does my Java app crash only when I minimize the RDP window?

Minimizing an RDP window often triggers a "disconnect" state rather than a full logout. If your application is tied to the interactive desktop, Windows may suspend or terminate graphics-dependent processes when the session is minimized to save resources. Running the app as a service removes this dependency on the graphical interface.

Can I run the Java application under my personal user account instead of System?

Yes, but you must ensure the task is configured to run whether the user is logged on or not. Using a dedicated service account is preferred for security and stability, as it avoids permission conflicts between different users who might log in simultaneously.

What is the difference between disconnecting and logging off in RDP?

Disconnecting keeps the session and its processes alive in the background, allowing you to reconnect later. Logging off terminates the session and all associated user processes. If your app restarts on logoff, it is likely triggered by a startup mechanism that fires for every new login event.

Does Windows Server 2022 handle RDP sessions differently than Windows 10?

Yes, Windows Server is designed for multi-user concurrent sessions and runs services in Session 0, which is isolated from user sessions. Consumer versions like Windows 10 Pro limit concurrent sessions and handle session states differently, often leading to confusion when migrating scripts or configurations.

How do I troubleshoot if the service fails to start?

Check the Windows Event Viewer under Applications and Services Logs > Microsoft > Windows > Service Control Manager. Look for error events corresponding to the time of the failure. Common issues include incorrect file paths in the service configuration or insufficient permissions for the service account to access the Java runtime environment.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More