shamim
shamim

Reputation: 6768

How to Automatically start Application

I work on C#.recently i work on Tcp server-client .I write a client application .want it's start automatically when client start os .Actually i have an exe,want it active when user start his computer.What i need to do?Thanks.if have any query plz ask.

Upvotes: 0

Views: 4960

Answers (5)

Jeetendra Negi
Jeetendra Negi

Reputation: 453

Add following code on your program first page....

    public string path;
    public string fileName;
    public void GetExeLocation()
    {
        path = System.Reflection.Assembly.GetEntryAssembly().Location; // for getting the location of exe file ( it can change when you change the location of exe)
        fileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; // for getting the name of exe file( it can change when you change the name of exe)
        StartExeWhenPcStartup(fileName,path); // start the exe autometically when computer is stared.
    }

    public void StartExeWhenPcStartup(string filename,string filepath)
    {
        Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        key.SetValue(filename, filepath);
    }

Upvotes: 2

Jude Cooray
Jude Cooray

Reputation: 19872

There are many ways that you can make an application start at run time.

For a list of locations. Check this article

To summarize they are

Start->Programs->StartUp folder

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\Run

Upvotes: 2

Grim
Grim

Reputation: 987

Making your server a windows service is a better option. This way even if the no one is logged on to the computer your program will start and run. Generally, services are a better choice for server applications requiring to run on OS startup.

You can read about how to create a service in C# in the following article

Upvotes: 0

TalkingCode
TalkingCode

Reputation: 13557

The Window Autostart Folder can be very useful. I normally put my applications there.

Upvotes: 0

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174369

Basically, there are two options:

  • Create a shortcut to your program in the Startup folder of your start menu
  • Create an entry in the registry in the Run key

Upvotes: 0

Related Questions