示例#1
0
            private void CreateUninstallShortCut(string targetPath)
            {
                bool createShortcuts = Runner.Variables.GetOptional <bool>(
                    Constants.ScriptVariables.CreateShortcuts
                    );

                if (!createShortcuts)
                {
                    return;
                }

                string startMenuPath = Runner.Variables.GetRequired <string>(
                    Constants.ScriptVariables.StartMenuPath
                    );

                string startMenuBase = NativeMethods.SHGetFolderPath(
                    IntPtr.Zero,
                    NativeMethods.SpecialFolderCSIDL.CSIDL_STARTMENU,
                    IntPtr.Zero,
                    0
                    );

                startMenuPath = Path.Combine(startMenuBase, startMenuPath);

                AddToInstallLog(new InstallLogCreateDirectory
                {
                    Path  = startMenuPath,
                    Force = false
                });

                Directory.CreateDirectory(startMenuPath);

                string shortcutFileName = Path.Combine(
                    startMenuPath,
                    UILabels.Uninstall + ".lnk"
                    );

                AddToInstallLog(new InstallLogCreateFile
                {
                    Path = shortcutFileName
                });

                _form.RaiseProgressChanged(String.Format(UILabels.CreatingShortcut, shortcutFileName));

                var shellLink = new ShellLink
                {
                    Target    = Path.Combine(targetPath, Constants.NuGetUpdateFileName),
                    IconIndex = 1,
                    IconPath  = Path.Combine(targetPath, Constants.NuGetUpdateFileName),
                    Arguments = String.Format("-r -p {0}", Escaping.ShellEncode(Runner.Environment.Config.PackageCode))
                };

                shellLink.SetPropertyValue(PropertyStoreProperty.AppUserModel_StartPinOption, 1 /* APPUSERMODEL_STARTPINOPTION_NOPINONINSTALL */);
                shellLink.SetPropertyValue(PropertyStoreProperty.AppUserModel_ExcludeFromShowInNewInstall, true);

                shellLink.Save(shortcutFileName);
            }