2012-06-07 139 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

相关问题