C#.Net
Introduction
Using the Library "StartupApplication"Below shown diagram is the class diagram for "SystemStartup" class defined in "StartupApplication" namespace.
In above class diagram you will see that "SystemStartup" class contains two nested classes "CurrentUser" and "AllUsers". Both these classes have two static methods "AddApplication" and "RemoveApplication".
To add a program to system's startup for a particular user we can use the following piece of code:-
To add a program to system's startup for all users just replcae "CurrentUser" with "AllUsers" in above code:-
To remove a program from system's startup for a particular user we can use the following piece of code:-
To remove a program from system's startup for all users just replcae "CurrentUser" with "AllUsers" in above code:-
One enumeration named "RunApplication" is also their in "System Startup" class as shown in its class diagram. This is used to specify Run or RunOnce feature of startup program.
Introduction
There are a number of ways by which a program can be launched automatically at Windows startup. We can write the path and name of the program to autoexec.bat or use Win32 API functions to write to the Load= or Run= lines of Win.ini. But the better methods to do the same are to use the registry or the system's Startup folder.
The Startup folder method is easy to use as we just need to place a shorcut of the application we want to run, in the system's Startup folder. To prevent that application from running at startup we can simply remove its shortcut from the system's Startup folder.
To use the registry we need to write the startup information in a specific registry key. We can write a value entry to any of the following registry keys as per requirement:- The Startup folder method is easy to use as we just need to place a shorcut of the application we want to run, in the system's Startup folder. To prevent that application from running at startup we can simply remove its shortcut from the system's Startup folder.
-
- HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
Used to launch a program when a particular user logs in. - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
- HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnceUsed to launch a program the next time when a particular user logs in and then removes its value entry from the registry.
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunUsed to launch a program at system startup irrespective of the user who logs in.
- HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceUsed to launch a program the next time when system starts and then removes its value entry from the registry.
Using the Library "StartupApplication"Below shown diagram is the class diagram for "SystemStartup" class defined in "StartupApplication" namespace.
In above class diagram you will see that "SystemStartup" class contains two nested classes "CurrentUser" and "AllUsers". Both these classes have two static methods "AddApplication" and "RemoveApplication".
To add a program to system's startup for a particular user we can use the following piece of code:-
SystemStartup.CurrentUser.AddApplication( "Name of the program", "Location of the program's exe file", SystemStartup.RunApplication.AlwaysAfterStartup );
To add a program to system's startup for all users just replcae "CurrentUser" with "AllUsers" in above code:-
SystemStartup.AllUsers.AddApplication( "Name of the program", "Location of the program's exe file", SystemStartup.RunApplication.AlwaysAfterStartup );
To remove a program from system's startup for a particular user we can use the following piece of code:-
SystemStartup.CurrentUser.RemoveApplication("Program Name");
To remove a program from system's startup for all users just replcae "CurrentUser" with "AllUsers" in above code:-
SystemStartup.AllUsers.RemoveApplication("Program Name");
One enumeration named "RunApplication" is also their in "System Startup" class as shown in its class diagram. This is used to specify Run or RunOnce feature of startup program.