-1

I have a remote computer that is always opened with a user, because I am using it as video player in which I have installed Kodi.

In this computer, I have a gRPC service installed, because I would like to can open some applications, close them and do a basic management from a mobile.

This gRPC service is hosted in a ASP Core application, that is installed as windows service. This services is running as SYSTEM user.

I am doing a test trying to open the notepad application, and it is opened, but as system user, so I can't see it in the user that is opened.

My question is, is it possible to open the notepad, or any other application, from this service and open in in the user that has the session opened to can see the notepad?

Perhaps one solution could be run the grpc service with this user, but I prefer to use the system user because some actions will need their permissions.

To open the notepad I am using this code:

ProcessStartInfo start = new ProcessStartInfo();
start.Arguments = string.Empty;
start.FileName = "notepad";
start.WindowStyle = ProcessWindowStyle.Hidden;
start.CreateNoWindow = true;

using (Process? proc = Process.Start(start))
{
    if (proc == null)
    {
        throw new ArgumentException("Handle error");
    }
}

Thanks.

Álvaro García
  • 18,114
  • 30
  • 102
  • 193
  • 2
    Does this answer your question? [Run a process from a windows service as the current user](https://stackoverflow.com/questions/15383684/run-a-process-from-a-windows-service-as-the-current-user) – GSerg Oct 23 '22 at 09:20
  • Does this answer your question? [How to start a process from windows service into currently logged in user's session](https://stackoverflow.com/q/4278373/11683) – GSerg Oct 23 '22 at 09:22

1 Answers1

1

According to documentation, the ProcessStartInfo class has settable properties for UserName and Password, which seems to me like the obvious solution to your problem (I Haven't tested that myself, though). You can even use the PasswordInClearText property though I think using a SecureString would probably be safer.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121