7

I would like to disable the lock screen after disconnecting from a remote desktop session in Windows 10.

Either natively, or with something like a .exe shortcut to disconnect from the session on the target machine.

Thorstein Nilsen
  • 73
  • 1
  • 1
  • 4
  • What do you mean by “disable”? Do you want Windows to automatically log in again after the remote session disconnects? – Daniel B Jan 25 '16 at 10:14
  • To clarify; when i disconnect from remote session, the lock screen on the target computer appears. I would either like to automatically log in again, like you say - or to disable the lock screen. – Thorstein Nilsen Jan 25 '16 at 20:26
  • 1
    You can’t disable the lock screen. The session will be disconnected from the console (the “real” PC) when you connect via RDP. This, in turn, brings up the lock screen, were you can read who is currently connected from where. – Daniel B Jan 25 '16 at 21:53

2 Answers2

10

In the end of your RDP session, open the Command prompt as Admin and:

tscon 1 /dest:console

when conected to the local console (using the /admin)

Luis Pereira
  • 161
  • 1
  • 5
0

Based on some work by subcoder, Uramanathan, Duncan, and Jimadine in another question where the answer was actually off-topic, I created a scheduled task that runs when closing/disconnecting the RDP connection the normal way (e.g. closing the RDP window). I'm reposting the answer here where it is firmly on-topic.

The task is triggered by the Microsoft-Windows-TerminalServices-LocalSessionManager/Operational event log getting a logoff event (EventID=24). Then it runs a simple command whenever a user logs off. The command gets the query session output which looks like:

SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc
>rdp-tcp#0         Matt                      2  Active
 console                                     5  Conn
 rdp-tcp                                 65536  Listen

It searches for %USERNAME% (in my case "Matt") and gets the ID column for that row. It passes the ID to the tscon command with %k /Dest:console, which unlocks the screen for the logged in user. This command probably only works if the user logging in remotely is the same user logged in locally, but I haven't tested.

Here's a task scheduler XML to import. The Author and UserId elements are removed and will be automatically filled in with your user when you import the task.

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2022-02-10T11:17:45.9347484</Date>
    <URI>\Unlock remote screen</URI>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-TerminalServices-LocalSessionManager/Operational"&gt;&lt;Select Path="Microsoft-Windows-TerminalServices-LocalSessionManager/Operational"&gt;*[System[Provider[@Name='Microsoft-Windows-TerminalServices-LocalSessionManager'] and (EventID=24)]]&lt;/Select&gt;&lt;Suppress Path="Microsoft-Windows-TerminalServices-LocalSessionManager/Operational"&gt;*[UserData[EventXML[Address="LOCAL"]]]&lt;/Suppress&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\cmd.exe</Command>
      <Arguments>/C "for /F "tokens=1,2,3 delims= " %i in ('query session ^| findstr "%USERNAME%"') do tscon %k /Dest:console"</Arguments>
      <WorkingDirectory>%USERPROFILE%</WorkingDirectory>
    </Exec>
  </Actions>
</Task>
Matt Chambers
  • 183
  • 1
  • 9