How can i add my applicaion on computer start up in Delphi

In Delphi, you can add your application to startup in several ways. One way is to create a Windows shortcut to your application and then add that shortcut to the Startup folder in the Start menu. Here are the steps in detail:

  1. Locate the executable file of your Delphi application. This is typically located in the project folder, in a subfolder called “Win32” or “Win64” depending on your build configuration.
  2. Right-click on the executable file and select “Create Shortcut” from the context menu. A new shortcut will be created in the same folder.
  3. Right-click on the newly created shortcut and select “Cut” from the context menu.
  4. Press the Windows key + R on your keyboard to open the Run dialog. Type “shell:startup” (without quotes) and press Enter. This will open the Startup folder in the Start menu.
  5. Right-click on an empty space in the Startup folder and select “Paste” from the context menu. This will add the shortcut to your application to the Startup folder.
  6. Close the Startup folder and restart your computer. Your application should now run automatically when Windows starts.

Another way is to add the following code in the FormCreate event of the mainform of your application:

This will add the application to the windows registry and the application will start automatically whenever the user logs in.

Note: Make sure you have the necessary permissions and your application will be compatible with the system requirements.

Another way to add your Delphi application to startup is by using the Windows API function “ShellExecute” to create a scheduled task that runs your application at startup. Here are the steps in detail:

  1. In your Delphi project, add the “Windows” unit to the uses clause of your main form’s unit.
  2. In the FormCreate event of your main form, add the following code:

This code retrieves the path and name of your application’s executable file, and then uses the ShellExecute function to create a scheduled task that runs your application at startup. The “/create” parameter creates a new task, the “/tn” parameter specifies the name of the task, the “/tr” parameter specifies the path to the application’s executable file, and the “/sc onstart” parameter specifies that the task should run at startup.

  1. After you run the application once, it will create the scheduled task in windows task scheduler, and it will start automatically every time the user logs in.

It’s important to note that in order to use the Windows API function “ShellExecute” to create a scheduled task, the user must have administrative privileges.

You can also use the third party software like nssm, to install your application as a windows service.

In summary, there are several ways to add your Delphi application to startup. You can create a Windows shortcut and add it to the Startup folder, add registry keys or use the Windows API to create a scheduled task. Each method has its own advantages and disadvantages, so you should choose the one that best suits your needs.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *