Search code examples
c#windowswinformsscheduled-taskswindows-server-2008

Run C# Winform Program on Remote Desktop Connection


Short version: How do I display my Winforms application to users remotely logging on in a Windows Server environment?

Background: I am deploying a C# Winforms application to a number of different Windows servers, some 2008 and some 2012. When a user logs on to one of these servers through remote desktop, I want the form to show up on the user's screen immediately. The program itself is a basic form which writes to the Windows Event Log in the Application section.

What works so far: I have successfully gotten the program to launch on a Windows Server 2008 machine when a user remotely logs on. I did this by creating a scheduled task which was triggered by user logon. Here's the batch file that did it:

SCHTASKS /Create /TN "MyLogonTask" /TR "C:\Path\To\Program.exe" /SC ONLOGON /IT

Here's the problem: When a user other than the one who created the task logs on, the form does not show up for them. To be more specific, the task does start, but the form only shows up for the user who created the task, RATHER THAN the user who actually logged on.

What I've done: I've tried changing the settings around inside the task, as well as launching the program with and without admin privileges. Also, I did try removing and recreating the task with different users, and every time the form only launched for the user who created the scheduled task. So far I have not had any luck with getting the program to display for the correct users.


Solution

  • You could place a shortcut in the StartUp folder. The location of this folder might vary by OS, but on 2012 R2, the user one is here:

    C:\Users\[USER]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
    

    and the machine one is here:

    C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp