开发者

c# Add application under startup through programme

Want to add/delete an Application under Windows-> All Programs -> StartUp thro开发者_高级运维ugh c# program.

Would appreciate the code / direction to do the above.

Regards Raju


you can run it every time windows start by using just 2 line of code below

    RegistryKey Key =  Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);                       
    Key.SetValue("AppName", System.Reflection.Assembly.GetEntryAssembly().Location);

If you realy need to create a startup shortcut, here is the code

  private void CreateShortcutInStartUP()
        {
            try
            {
                Assembly code = Assembly.GetExecutingAssembly();
                String company =  Application.CompanyName;
                String ApplicationName = Application.ProductName;

                if( company != "" && ApplicationName != "") 
                {
                    String DesktopPath= Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + ApplicationName + @".appref-ms";
                    String ShortcutName= Environment.GetFolderPath(Environment.SpecialFolder.Programs) + @"\" + company + @"\" + ApplicationName + @".appref-ms";
                    if (System.IO.File.Exists(ShortcutName))
                        System.IO.File.Copy(ShortcutName, DesktopPath, true);

                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

I am currently using above code so you can just copy paste. Make sure you have setup company name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜