2012-06-07 74 views
11

使用Mage創建的ClickOnce應用程序未顯示在控制面板添加或刪除程序中爲Mage命令行參數指定的圖標。「添加或刪除程序」中的ClickOnce應用程序的自定義圖標

我讀一些博客,比如:

我怎樣才能做到這一點無需編輯註冊表項?可能嗎?

+0

相關:* [在「添加或刪除程序」圖標ClickOnce應用程序(http://stackoverflow.com/questions/13265806/)* –

回答

14

在沒有編輯註冊表的情況下沒有辦法做到這一點,但是您可以通過編程來完成。您必須確保該圖標包含在部署中。我們將我們的程序集描述設置爲與我們的產品名稱相同的字符串,因此我們可以通過搜索程序集描述來查看正確應用程序的卸載字符串。這樣,我們不必在此代碼中對產品名稱進行硬編碼。

 private static void SetAddRemoveProgramsIcon() 
    { 
     //only run if deployed 
     if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed 
      && ApplicationDeployment.CurrentDeployment.IsFirstRun) 
     { 
      try 
      { 
       Assembly code = Assembly.GetExecutingAssembly(); 
       AssemblyDescriptionAttribute asdescription = 
        (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code, typeof(AssemblyDescriptionAttribute)); 
       string assemblyDescription = asdescription.Description; 

       //the icon is included in this program 
       string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "youriconfile.ico"); 

       if (!File.Exists(iconSourcePath)) 
        return; 

       RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall"); 
       string[] mySubKeyNames = myUninstallKey.GetSubKeyNames(); 
       for (int i = 0; i < mySubKeyNames.Length; i++) 
       { 
        RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true); 
        object myValue = myKey.GetValue("DisplayName"); 
        if (myValue != null && myValue.ToString() == assemblyDescription) 
        { 
         myKey.SetValue("DisplayIcon", iconSourcePath); 
         break; 
        } 
       } 
      } 
      catch (Exception ex) 
      { 
       //log an error 
      } 
     } 
    } 
+0

你從哪裏跑的? – HackSlash

相關問題