Example #1
0
        /// <summary>
        /// 단축아이콘의 아이콘을 실행파일의 아이콘으로 변경함.
        /// </summary>
        /// <param name="ExePath"></param>
        /// <param name="ExeFile"></param>
        public static void ChangeShortcutIconWithExeIcon(string ExePath, string ExeFile)
        {
            string ExeFileNoExt = CPath.GetFileNameWithoutExtension(ExeFile);

            string[] aPathFile =
                new String[]
            {
                Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Internet Explorer\Quick Launch",
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                Environment.GetFolderPath(Environment.SpecialFolder.Programs),
                Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)
            };

            Type   typWsh  = Type.GetTypeFromProgID("WScript.Shell");
            object instWsh = Activator.CreateInstance(typWsh);

            for (int i = 0, i2 = aPathFile.Length; i < i2; i++)
            {
                FileInfo fi = CFile.FindFirstFile(aPathFile[i], ExeFileNoExt + ".lnk", true);
                if (fi != null)
                {
                    string PathFile = (string)fi.FullName;

                    object Shortcut = typWsh.InvokeMember(
                        "CreateShortcut",
                        BindingFlags.InvokeMethod | BindingFlags.Public,
                        null,
                        instWsh,
                        new object[1] {
                        PathFile
                    });

                    Type typShortcut = Shortcut.GetType();
                    typShortcut.InvokeMember(
                        "IconLocation",
                        BindingFlags.SetProperty | BindingFlags.Public,
                        null,
                        Shortcut,
                        new object[1] {
                        ExePath + "\\" + ExeFile
                    });

                    typShortcut.InvokeMember(
                        "Save",
                        BindingFlags.InvokeMethod | BindingFlags.Public,
                        null,
                        Shortcut,
                        null);
                }
            }
        }