Reputation: 89
I'm working on a C# application on Windows 11 (version 23H2) that aims to create a user session (remote desktop session) from a Windows service. The goal is to launch an application within that session and then terminate the session.
Here's where I'm encountering issues:
APIs Used:
LogonUser
(advapi32.dll): This seems to be working fine, presumably creating the user session.DuplicateToken
(advapi32.dll): Successfully duplicates the obtained user token for application launch.CreateProcessAsUser
(advapi32.dll): To launch the desired application within the newly created session and This is where things go wrong.Errors:
@"C:\windows\System32\calc.exe"
): Throws a System.Runtime.InteropServices.SEHException
with the message "External component has thrown an exception."
@"C:\windows\System32\notepad.exe"
): Throws a System.ComponentModel.Win32Exception
with the message "The system cannot find the file specified." (Interestingly, this path works when launching from the command prompt.)What I Expected:
CreateProcessAsUser
to successfully launch the specified application (Calculator or Notepad) within the newly created user session.
Upvotes: 0
Views: 84