23

I am trying to create and install a .NET app on a windows server that is always on, but I am running into problems. I have heard that I should not make it a Windows service (and would personally rather have a dialog app so I can see progress, etc) so I am trying to use the task scheduler. However, the task scheduler keeps trying to close my app prematurely, when it should only open it and leave it open.

Any ideas how I could have my dialog app run on startup (and stay running) on my server?

dbc
  • 104,963
  • 20
  • 228
  • 340
Rob
  • 7,028
  • 15
  • 63
  • 95
  • Ok so I've gotten it to work by creating a program that opens my main program, and having task scheduler open the first one. Somehow I don't think this is the best way of doing it, any other suggestions (other than making a service)? – Rob May 13 '11 at 02:48

4 Answers4

29

You can do it with a Scheduled Task which wont have problems with users logging on/off.

  1. Open Task Scheduler, Windows Key + R

Taskschd.msc

  1. Click Action menu > Create Task

enter image description here

  1. Change the User to a Administrator or preferably a Service Account and note the option to Run whether user is logged in "or not":

enter image description here

4a. Set At Log On

enter image description here

or 4b. On a schedule to work regardless of users being logged in:

enter image description here

  1. Set a program to start:

enter image description here

NOTE: Please use a Service Account to do this, if you use your Admin account then it will FAIL after changing password,

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
11

It's a very old question, but for those who coming here via Google:

Start the command prompt and type shell:Startup

This will open a window in the otherwise hidden AppData path for the Startmenu/Programs/Startup -> Add a shortcut to the executable for the program you want to start.

This will of course only apply to the logon account that you're using at the time.

For all users type shell:Common Startup

Ali
  • 2,702
  • 3
  • 32
  • 54
Atul
  • 3,778
  • 5
  • 47
  • 87
  • "The filename, directory name, or volume label syntax is incorrect.". Does this only work in non-Server Windows? (I'm using Server 2016). – Steve Smith Jan 10 '23 at 11:13
10

You should make a Windows Service; it's the only reliable way to do this.
Otherwise, you will run into problems if, for example, the user logs off.

If you want UI, you can make a separate GUI that communicates with the service (probably using WCF).

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • How could I still have the service provide feedback, and be able to turn it on/ off on the fly? – Rob May 13 '11 at 02:18
  • Could he make a Windows Service that ensured his dialog app was always running? – Grokodile May 13 '11 at 02:19
  • 1
    Write a GUI that communicates with (using WCF) and controls (using `ServiceController`) the service. – SLaks May 13 '11 at 02:20
  • @panamack: That's an even worse idea. – SLaks May 13 '11 at 02:21
  • Is there any way I could get scheduler to do it? I really don't think a service is necessary – Rob May 13 '11 at 02:24
  • 1
    Perhaps, but I recommend against it. For one thing, it will be more difficult to maintain. – SLaks May 13 '11 at 02:26
  • How would it be more difficult to maintain? We are constantly going to be editing the program so a service seems a bit overkill – Rob May 13 '11 at 02:28
  • Wow you're right, I'm really starting to run into log on issues (apparently user interfaces cannot load unless a user is logged on). What a pain in the ass... I think I'm going to take your suggestion and just make a service, unless someone else has another suggestion. What happened to just putting a program into the startup folder, or changing some settings in the registry? – Rob May 13 '11 at 07:15
  • 1
    @Rob: Those are for _logged in_ users. – SLaks May 13 '11 at 11:49
5

I prefer to create a task in the Task Scheduler and set the trigger as "On Startup", but you can also use Startup Scripts.

You can also use the Local Group Policy Editor (executing gpedit) and add a Startup script. Copying the steps from http://technet.microsoft.com/en-us/library/cc770556.aspx so that if they take it down, it still can be found at SO.

To assign computer startup scripts

  1. Open the Local Group Policy Editor.
  2. In the console tree, click Scripts (Startup/Shutdown). The path is Computer Configuration\Windows Settings\Scripts (Startup/Shutdown).
  3. In the results pane, double-click Startup.
  4. In the Startup Properties dialog box, click Add.
  5. In the Add a Script dialog box, do the following:
    • In the Script Name box, type the path to the script, or click Browse to search for the script file in the Netlogon shared folder on the domain controller.
    • In the Script Parameters box, type any parameters that you want, the same way as you would type them on the command line. For example, if your script includes parameters called //logo (display banner) and //I (interactive mode), type //logo //I.
  6. In the Startup Properties dialog box, specify the options that you want:
    • Startup Scripts for <Group Policy object>: Lists all the scripts that currently are assigned to the selected Group Policy object (GPO). If you assign multiple scripts, the scripts are processed in the order that you specify. To move a script up in the list, click it and then click Up. To move a script down in the list, click it and then click Down.
    • Add: Opens the Add a Script dialog box, where you can specify any additional scripts to use.
    • Edit: Opens the Edit Script dialog box, where you can modify script information, such as name and parameters.
    • Remove: Removes the selected script from the Startup Scripts list.
    • Show Files: Displays the script files that are stored in the selected GPO.
g3rv4
  • 19,750
  • 4
  • 36
  • 58