0

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.

5 Answers 5

2

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

2

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);
    }
0

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
1
  • will you plz tell me how to add on registry.
    – shamim
    May 5, 2011 at 8:32
0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.