JG Vimalan's Blog

It is all about coding!

Auto start .NET application on system reboot

Inorder to start you .net application whenever system starts, you need to set the application path in the registry. In registry, there is a special location called ‘Run’ under SOFTWARE\Microsoft\Windows\CurrentVersion\. You need to make an entry in the ‘Run’ key for starting your application on every reboot.

The following code snippet will give a quick idea on setting entry in the ‘Run’ key,

internal void SetStartUp()
        {
            System.IO.Directory.SetCurrentDirectory(
                System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
            string path = System.IO.Path.GetDirectoryName(
                System.Reflection.Assembly.GetExecutingAssembly().Location) + “\\mygametray.exe“;       

            var rkApp = Registry.LocalMachine.OpenSubKey(@”SOFTWARE\Microsoft\Windows\CurrentVersion\Run”, true);
            if (rkApp.GetValue(“mygametray”) == null)
            {
                rkApp.SetValue(“mygametray “, ‘”‘ + path + ‘”‘);
            }
            rkApp.Close();
        }

You need to perform this action while performing installation.

Advertisements

November 26, 2010 - Posted by | C#.NET

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: