0

I have created the following scheduled task using an Administrator cmd.exe:

schtasks /CREATE /RU SYSTEM /SC ONLOGON /TN SYSTEM_notepad /TR C:\Windows\System32\notepad.exe

The scheduled task runs just fine on LOGON:

enter image description here

However, notepad.exe is nowhere to be seen in the GUI.

Why is my scheduled task running in the "background" without any GUI? How can I fix this?

Shuzheng
  • 419
  • 1
  • 8
  • 15

1 Answers1

2

Because you have /RU SYSTEM. The system account is a special account and doesn't have a session with GUI like any account used for login. It's designed e.g. for unattended services that needs to run even when users aren't logged in. You can't log in as SYSTEM.

Using Notepad as an example completely masks your true needs, but maybe (based on the comment) you are trying to build something that would actually need an architecture of an Interactive Service with a separate GUI client:

  1. Service starts without GUI during system startup.
  2. Hidden GUI client starts separately for every user session during login.
  3. The service communicates with the client, causing it to display the GUI whenever required.

Create a separate hidden GUI application and use the CreateProcessAsUser function to run the application within the context of the interactive user. Design the GUI application to communicate with the service through some method of interprocess communication (IPC), for example, named pipes. The service communicates with the GUI application to tell it when to display the GUI. The application communicates the results of the user interaction back to the service so that the service can take the appropriate action. Note that IPC can expose your service interfaces over the network unless you use an appropriate access control list (ACL).

If this service runs on a multiuser system, add the application to the following key so that it is run in each session: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. If the application uses named pipes for IPC, the server can distinguish between multiple user processes by giving each pipe a unique name based on the session ID.

Don't try to use Windows Task Scheduler for this purpose, but design your software better.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • Thank you - How would I then configure a task that runs for every user and displays the GUI of the task? Notepad.exe is just an example... Would you link to a resource that states that SYSTEM doesn't have a sessions with a GUI? – Shuzheng Jun 28 '18 at 08:04