SetAddRemoveProgramsIcon
C
code posted
by
RuWi
created at 05 Mar 13:20
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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 } } } |
1.67 KB in 3 ms with coderay