Automatically run program on Windows Server startup

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

  1. Set At Log On:

enter image description here

  1. Set a program to start:

enter image description here


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).


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


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.

Tags:

C#

Vb.Net