`

(转)我的电脑中创建图标

    博客分类:
  • c#
阅读更多
public static void CreateShortCutByMyComputer(Guid id, string name, string description, string path, string icon)
        {
            RegistryKey root = Registry.ClassesRoot;
            RegistryKey clsid = root.OpenSubKey("CLSID", true);
            RegistryKey key = CreateOrGetSubKey(clsid, string.Format("{{{0}}}", id));
            key.SetValue("", name);
            key.SetValue("InfoTip", description);
            key.SetValue("LocalizedString", name);
            key.SetValue("System.ItemAuthors", description);
            key.SetValue("TileInfo", "prop:System.ItemAuthors");
 
            RegistryKey defaultIcon = CreateOrGetSubKey(key, "DefaultIcon");
            defaultIcon.SetValue("", icon);
            RegistryKey inProcServer32 = CreateOrGetSubKey(key, "InProcServer32");
            inProcServer32.SetValue("", @"%SystemRoot%\system32\shell32.dll");
            inProcServer32.SetValue("ThreadingModel", "Apartment");
            RegistryKey shell = CreateOrGetSubKey(key, "Shell");
            RegistryKey open = CreateOrGetSubKey(shell, "Open");
            RegistryKey command = CreateOrGetSubKey(open, "Command");
            command.SetValue("", path);
            RegistryKey shellFolder = CreateOrGetSubKey(key, "ShellFolder");
            shellFolder.SetValue("Attributes", new byte[] { 00, 00, 00, 00 }, RegistryValueKind.Binary);
 
 
            RegistryKey hcu = Registry.CurrentUser;
            RegistryKey ns = hcu.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer").OpenSubKey("MyComputer").OpenSubKey("NameSpace", true);
            RegistryKey v = CreateOrGetSubKey(ns, string.Format("{{{0}}}", id));
            v.SetValue("", name);
        }
 
        public static void RemoveShortCutByMyComputer(Guid id)
        {
            RegistryKey root = Registry.ClassesRoot;
            RegistryKey clsid = root.OpenSubKey("CLSID", true);
            clsid.DeleteSubKeyTree(string.Format("{{{0}}}", id), true);
 
            RegistryKey hcu = Registry.CurrentUser;
            RegistryKey ns = hcu.OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Explorer").OpenSubKey("MyComputer").OpenSubKey("NameSpace", true);
            ns.DeleteSubKey(string.Format("{{{0}}}", id), true);
        }

 原文地址:http://www.cnblogs.com/xsi640/p/3548312.html

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics