2010-07-14 130 views

回答

8

你可以運行它的每一個時間窗口使用下面

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

只有2行代碼開始如果你真的需要創建啓動快捷方式,這裏是代碼

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

我目前使用上面的代碼,所以你可以複製粘貼。確保你有設置公司名稱。

+0

using System.Reflection; – Eric 2016-07-06 18:45:59

相關問題