示例#1
0
        /// <summary>
        /// SendTo Command
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSendTo_Click(object sender, EventArgs e)
        {
            string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.SendTo);
            string link = string.Format(@"{0}\{1}.lnk", path, this.Text);

            if (!SendToFlag)
            {
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                IWshRuntimeLibrary.IWshShortcut SendTo = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(link);

                SendTo.TargetPath       = this.GetType().Assembly.Location;
                SendTo.Arguments        = "";
                SendTo.Description      = "Windows系统快捷方法创建工具";
                SendTo.WorkingDirectory = System.Environment.CurrentDirectory;
                SendTo.IconLocation     = string.Format("{0},0", this.GetType().Assembly.Location);
                SendTo.Hotkey           = "CTRL+S";
                SendTo.WindowStyle      = 1;
                SendTo.Save();
                Msg("删除\"发送到\"命令完成", MSG_TYPE.ERROR);
            }
            else
            {
                System.IO.File.Delete(link);
                Msg("删除\"发送到\"命令完成", MSG_TYPE.GREEN);
            }
            GetSendToButtonStatus();
        }
示例#2
0
        /// <summary>
        /// Parses the shortcut specifed and returns the path to the executable it references
        /// </summary>
        /// <param name="file">The path of the shortcut</param>
        /// <returns>
        /// The path of the executable or <c>null</c> if the shortcut could not be parsed
        /// </returns>
        public static string Parse(string file)
        {
            StringBuilder product = new StringBuilder(MaxGuidLength + 1);
            StringBuilder feature = new StringBuilder(MaxFeatureLength + 1);
            StringBuilder component = new StringBuilder(MaxGuidLength + 1);

            MsiGetShortcutTarget(file, product, feature, component);

            int pathLength = MaxPathLength;
            StringBuilder path = new StringBuilder(pathLength);

            InstallState installState = MsiGetComponentPath(product.ToString(), component.ToString(), path, ref pathLength);
            if (installState == InstallState.Local)
            {
                return path.ToString();
            }
            else
            {
                Wsh.WshShell shell = new Wsh.WshShell(); //Create a new WshShell Interface
                Wsh.IWshShortcut link = (Wsh.IWshShortcut)shell.CreateShortcut(file);
                if (link != null)
                    return link.TargetPath; //Link the interface to our shortcut
                return null;
            }
        }
示例#3
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);
 }
示例#4
0
        static void Main(string[] args)
        {
            pathStringBuilder path = new pathStringBuilder();

            //Console.WriteLine(path.BuildFullPath());
            //Console.WriteLine(path.BuildFolderName());
            Console.WriteLine(path.BuildDesktopShortcutPath());

            //Console.ReadKey();
            //Comment in the below for production
            //Directory.CreateDirectory(path.BuildFullPath());



            void CreateShortcut(string linkPath, string filename)
            {
                // Create shortcut dir if not exists
                if (!Directory.Exists(linkPath))
                {
                    Directory.CreateDirectory(linkPath);
                }

                // COM object instance/props
                IWshRuntimeLibrary.WshShell     shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut sc    = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filename);
                sc.Description = "Shortcut to today's shortcut folder.";
                //shortcut.IconLocation = @"C:\...";
                sc.TargetPath = linkPath;//ADAM:---------------this needs to be the path to the folder
                // save shortcut to target
                sc.Save();
            }

            CreateShortcut(path.BuildFullPath(), path.BuildDesktopShortcutPath());
        }
示例#5
0
 public static void CreateShortcut(string executable, string arguments, string description, string destination, string iconPath = null)
 {
     Wsh.WshShell shell = new Wsh.WshShell();
     Wsh.IWshShortcut shortcut = (Wsh.IWshShortcut)shell.CreateShortcut(destination);
     shortcut.Description = description;
     shortcut.TargetPath = executable;
     shortcut.Arguments = arguments;
     if (iconPath != null)
         shortcut.IconLocation = iconPath;
     shortcut.Save();
 }
示例#6
0
        /// <summary>
        /// 実行ボタンクリック時のイベント
        /// </summary>
        /// <param name="sender">使用しない</param>
        /// <param name="e">使用しない</param>
        private async void Button_Click_Enter(object sender, RoutedEventArgs e)
        {
            var targetPath = this.TargetPathText.Text;

            if (!IO.Directory.Exists(targetPath))
            {
                MessageBox.Show($"ディレクトリ「{targetPath}」が見つかりませんでした。", "エラー");
            }

            try
            {
                // 相互運用型のため、対応するインターフェースを通じてインスタンスを生成。
                var sh = new Wsh.WshShell();

                foreach (var file in IO.Directory.GetFiles(targetPath, "*.lnk", IO.SearchOption.AllDirectories))
                {
                    var filePath = ((Wsh.IWshShortcut)sh.CreateShortcut(file)).TargetPath;

                    if (IO.File.Exists(filePath))
                    {
                        // ボトルネック解消のため。
                        await Task.Run(() =>
                        {
                            var next = IO.Path.Combine(IO.Path.GetDirectoryName(file), IO.Path.GetFileName(filePath));
                            IO.File.Copy(filePath, next);

                            var fileInfo = new FileInfo(file);
                            if ((fileInfo.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                            {
                                fileInfo.Attributes = FileAttributes.Normal;
                            }

                            fileInfo.Delete();
                        });
                    }
                }

                MessageBox.Show("コピーが完了しました。", "完了");
            }
            catch (IOException)
            {
                MessageBox.Show("入出力に関する例外が発生しました。\n開発者にお問い合わせください。");
            }
            catch (OutOfMemoryException)
            {
                // 以下のcatchでOutOfMemoryExceptionをcatchしないため。
                throw;
            }
            catch
            {
                MessageBox.Show("不明な例外が発生しました。\n開発者にお問い合わせください。");
            }
        }
示例#7
0
        private void AddShortcut(string shortCutPath)
        {
            shellLib.WshShell shell = new shellLib.WshShell();

            string shortcutPath = shortCutPath;

            shellLib.IWshShortcut shortcut = (shellLib.IWshShortcut)shell.CreateShortcut(shortcutPath);
            shortcut.Description = "Ярлык для терминала CTC";
            //string terminalDir = Environment.GetEnvironmentVariable("TERMINAL_PATH");
            shortcut.TargetPath = PathTerminalExecDir + @"\Terminal.exe";  //Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";

            shortcut.Save();
        }
示例#8
0
        public void MakeLauncher(string command, string args, string launcherPath)
        {
            string shortcutFilePath = Path.ChangeExtension(
                launcherPath, ShortcutExtension);
            WshShell    wshShell = new IWshRuntimeLibrary.WshShell();
            WshShortcut shortcut = (WshShortcut)wshShell
                                   .CreateShortcut(shortcutFilePath);

            shortcut.TargetPath = command;
            shortcut.Arguments  = args;
            shortcut.Save();
            return;
        }
示例#9
0
        public static void CreateShortCut()
        {
            var          path     = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\Backupper.lnk";
            WshShell     wsh      = new IWshRuntimeLibrary.WshShell();
            IWshShortcut shortcut = wsh.CreateShortcut(path) as IWshShortcut;

            shortcut.Arguments        = "";
            shortcut.TargetPath       = Environment.CurrentDirectory + @"\UsbBackupper.exe";
            shortcut.WindowStyle      = 1;
            shortcut.Description      = "backupper";
            shortcut.WorkingDirectory = Environment.CurrentDirectory + @"\";
            shortcut.Save();
        }
示例#10
0
        public void CreateIcon()
        {
            string dt = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            dt += "\\ScreenSnip.lnk";

            string shortcutLocation = dt;

            WSH.WshShell     shell    = new WSH.WshShell();
            WSH.IWshShortcut shortcut = (WSH.IWshShortcut)shell.CreateShortcut(shortcutLocation);
            shortcut.Description = "WolfPaw Screen Snipper tool";
            shortcut.TargetPath  = Properties.Settings.Default.s_Path + "\\WolfPaw ScreenSnip.exe";
            shortcut.Save();
        }
示例#11
0
        private void ItemAutoStart_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.MenuItem item = sender as System.Windows.Forms.MenuItem;
            item.Checked = !item.Checked;
            string startupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            if (item.Checked)
            {
                try
                {
                    string linkFile = startupPath + "\\VolumnUtility.lnk";
                    var    shell    = new IWshRuntimeLibrary.WshShell();
                    var    shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkFile);
                    shortcut.TargetPath       = Assembly.GetEntryAssembly().Location;
                    shortcut.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
                    shortcut.Save();

                    XDocument doc     = new XDocument();
                    XElement  root    = new XElement("config");
                    XElement  startup = new XElement("autostart");
                    startup.SetValue(1);
                    root.Add(startup);
                    doc.Add(root);
                    doc.Save(AppDomain.CurrentDomain.BaseDirectory + "config.xml");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                string[] files = Directory.GetFiles(startupPath);
                foreach (var file in files)
                {
                    if (Path.GetFileName(file).Trim() == "VolumnUtility.lnk")
                    {
                        System.IO.File.Delete(file);
                        break;
                    }
                }
                XDocument doc     = new XDocument();
                XElement  root    = new XElement("config");
                XElement  startup = new XElement("autostart");
                startup.SetValue(0);
                root.Add(startup);
                doc.Add(root);
                doc.Save(AppDomain.CurrentDomain.BaseDirectory + "config.xml");
            }
        }
示例#12
0
        /// <summary>
        /// Creates executable shortcut to the mod
        /// </summary>
        public void CreateExe()
        {
            string path      = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            object shDesktop = (object)"Desktop";

            wsh.WshShell shell           = new wsh.WshShell();
            string       shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Ucieczka.lnk";

            wsh.IWshShortcut shortcut = (wsh.IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.Description  = "Uruchom modyfikację G2 Ucieczka";
            shortcut.TargetPath   = window.GothicPath + @"\System\Gothic2.exe";
            shortcut.IconLocation = window.GothicPath + @"\System\Ucieczka.ico";
            shortcut.Arguments    = "-game:Ucieczka.ini";
            shortcut.Save();
        }
示例#13
0
        /// <summary>
        /// 生成快捷方式
        /// </summary>
        /// <param name="appName">快捷方式名称</param>
        /// <param name="appPath">要创建路径</param>
        /// <returns>成功与否</returns>
        public static bool CreatShortCut(String appName, String appPath)
        {
            if (!System.IO.File.Exists(appPath))
            {
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(appPath);

                shortcut.Description = AppInfo.AppName + AppInfo.AppVersion;
                shortcut.TargetPath = System.Environment.CurrentDirectory + "\\DeepOcean.exe";

                shortcut.IconLocation = System.Environment.CurrentDirectory + "\\icon.png";
                shortcut.Save();
                return true;
            }
            return false;
        }
示例#14
0
        public static void CreateDesktopLnk(string AppPath)
        {
            string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹

            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\GBT.lnk");
            shortcut.TargetPath       = AppPath + "GBT.exe";
            shortcut.Arguments        = "";                                  //参数
            shortcut.Description      = "http://gamelab.1111";
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
            shortcut.IconLocation     = AppPath + "GBT.exe,0";               //图标
            shortcut.Hotkey           = "";                                  //热键
            shortcut.WindowStyle      = 1;
            shortcut.Save();
        }
示例#15
0
 string CreateShortcut(string exe, string shortcutFileLocation)
 {
     try
     {
         var    shell           = new WSH.WshShell();
         string shortcutAddress = Path.Combine(shortcutFileLocation, "LogJoint.lnk");
         var    shortcut        = (WSH.IWshShortcut)shell.CreateShortcut(shortcutAddress);
         shortcut.Description = "LogJoint Log Viewer";
         shortcut.TargetPath  = exe;
         shortcut.Save();
         return(shortcutAddress);
     }
     catch (Exception e)
     {
         warnings.AppendLine("Failed to create shortcut in '" + shortcutFileLocation + "': " + e.Message);
         return(null);
     }
 }
示例#16
0
        private void panel2_MouseClick(object sender, MouseEventArgs e)
        {
            ofd = new OpenFileDialog
            {
                //InitialDirectory = @"D:\",
                Title            = "Selectati aplicatia",
                DereferenceLinks = false,
                CheckFileExists  = true,
                CheckPathExists  = true,
                ShowReadOnly     = true,
                Filter           = "Object Files (*.exe)|*.exe",
                FilterIndex      = 0,
            };
            ofd.ShowDialog();
            if (!string.IsNullOrWhiteSpace(ofd.FileName))
            {
                safefilename = despartire(ofd.FileName);
                try
                {
                    IWshRuntimeLibrary.WshShell     w = new IWshRuntimeLibrary.WshShell();
                    IWshRuntimeLibrary.IWshShortcut s = (IWshShortcut)w.CreateShortcut(ofd.FileName.Trim());
                    adaugare(s.TargetPath, safefilename, despartire(s.TargetPath));
                }
                catch (Exception)
                {
                    adaugare(ofd.FileName, safefilename, despartire(ofd.SafeFileName));
                }

                if (!string.IsNullOrWhiteSpace(cale))
                {
                    listView1.Clear();
                    listView1.Columns.Add("Nume Aplicatie", -2);
                    fill();
                }
                fillista();
                fillProcessList();
                listView1.Invalidate();
                //     listView1_DrawSubItem(this, new DrawListViewSubItemEventArgs(listView1.CreateGraphics(), item.Bounds, item, null, listView1.Items.Count, 0, null, ListViewItemStates.Default));
            }
        }
示例#17
0
        private static void SetAutoStart(string directory, string shortcutName, string targetPath,
                                         string description = null, string iconLocation = null)
        {
            if (IsAutoStart(directory, targetPath))
            {
                return;
            }
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            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();
        }
示例#18
0
 /// <summary>
 /// Create Shortcut
 /// </summary>
 /// <param name="dir"></param>
 /// <param name="name"></param>
 /// <param name="target_path"></param>
 /// <returns></returns>
 private Boolean CreateShortcut(String dir, String name, String target_path)
 {
     try
     {
         if (!Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         String       shortcutPath = Path.Combine(dir, String.Format("{0}.lnk", name));
         WshShell     shell        = new IWshRuntimeLibrary.WshShell();
         IWshShortcut wshShortcut  = shell.CreateShortcut(shortcutPath) as IWshShortcut;
         wshShortcut.TargetPath       = target_path;
         wshShortcut.WorkingDirectory = Path.GetDirectoryName(target_path);
         wshShortcut.WindowStyle      = 1;
         wshShortcut.Save();
         return(true);
     }
     catch (Exception ex)
     {
         ErrMsg += ex.Message + ';';
     }
     return(false);
 }
示例#19
0
 /// <summary>
 /// 创建快捷键
 /// </summary>
 /// <param name="pathLink">快捷键路径</param>
 /// <param name="shortcutName">快捷方式名称</param>
 /// <param name="appName">应用</param>
 /// <param name="ico">图标</param>
 static void CreateLink(string pathLink, string shortcutName, string appName, string ico)
 {
     try
     {
         pathLink = Path.Combine(pathLink, shortcutName + ".lnk");
         //如果存在快捷键,先删除
         if (File.Exists(pathLink))
         {
             File.Delete(pathLink);
         }
         SHORT.WshShell     shell    = new SHORT.WshShell();
         SHORT.IWshShortcut shortcut = shell.CreateShortcut(pathLink);
         shortcut.TargetPath       = Path.Combine(_rootDir, appName);
         shortcut.WorkingDirectory = _rootDir;
         shortcut.Description      = shortcutName;
         shortcut.IconLocation     = ico;
         shortcut.WindowStyle      = 1;
         shortcut.Save();
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#20
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            if (li == 1)
            {
                if (Directory.Exists(drive + @"\\App"))
                {
                    ZipFile.ExtractToDirectory("config\\data\\install\\install.App", drive + "\\App\\");
                    System.Diagnostics.Process.Start(drive + "\\App\\" + sc + "\\" + sc1 + ".exe");
                    string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹
                    IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();



                    IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\" + sc1 + ".lnk");
                    shortcut.TargetPath       = drive + "\\App\\" + sc + "\\" + sc1 + ".exe";
                    shortcut.Arguments        = "";                                                  // 参数
                    shortcut.Description      = "Applications";
                    shortcut.WorkingDirectory = drive + "\\App\\" + sc;                              //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
                    shortcut.IconLocation     = drive + "\\App\\" + sc + "\\" + sc1 + ".exe" + ",0"; //图标
                    shortcut.Hotkey           = "";                                                  //热键
                    shortcut.WindowStyle      = 1;
                    shortcut.Save();

                    shortcut.Save();//保存快捷方式
                    MessageBox.Show("安装成功", "Done 完成");
                }
                else
                {
                    Directory.CreateDirectory(drive + @"\\App");
                }
                li = 0;
            }
            else
            {
            }
        }
        /// <summary>
        /// 单击开机自启按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ChkStartupClickEventHandler(object sender, RoutedEventArgs e)
        {
            if (((CheckBox)sender).IsChecked == true)
            {
                string Path = Environment.GetFolderPath(Environment.SpecialFolder.Startup);// System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\新建文件夹 (3)"; //"%USERPROFILE%\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";

                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
                IWshShortcut sc = (IWshShortcut)shell.CreateShortcut(Path + "\\FloatClipBoard.lnk");
                sc.TargetPath       = Process.GetCurrentProcess().MainModule.FileName;
                sc.WorkingDirectory = Environment.CurrentDirectory;
                sc.Save();
                //Debug.WriteLine(Path);
                if (System.IO.File.Exists(Path + "\\FloatClipBoard.lnk"))
                {
                    MessageBox.Show("成功", "结果", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("失败", "结果", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                string Path = Environment.GetFolderPath(Environment.SpecialFolder.Startup);// System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "\\新建文件夹 (3)"; //"%USERPROFILE%\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";

                System.IO.File.Delete(Path + "\\FloatClipBoard.lnk");
                if (System.IO.File.Exists(Path + "\\FloatClipBoard.lnk"))
                {
                    MessageBox.Show("失败", "结果", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    MessageBox.Show("成功", "结果", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
        private void QuickSetup_Click(object sender, MouseButtonEventArgs e)
        {
            try
            {
                //Release files.
                ((sender as Label).Parent as Border).Visibility = Visibility.Hidden;
                customLabel.Visibility = Visibility.Hidden;
                progressBar.Maximum    = 100;
                PBSetValue(1);

                byte[] package   = Properties.Resources.package;
                byte[] uninstall = Properties.Resources.LiteQnaire_Uninstallor;
                PBSetValue(5);

                if (!Directory.Exists(sInfo.path))
                {
                    Directory.CreateDirectory(sInfo.path);
                }
                string pkgPath = sInfo.path + "\\package.pkg";
                PBSetValue(15);

                FileStream fStream = new FileStream(pkgPath, FileMode.Create);
                fStream.Write(package, 0, package.Length);
                fStream.Flush();
                fStream.Close();

                fStream = new FileStream(sInfo.path + "\\Uninstall.exe", FileMode.Create);
                fStream.Write(uninstall, 0, uninstall.Length);
                fStream.Flush();
                fStream.Close();
                PBSetValue(20);

                if (!File.Exists(pkgPath))
                {
                    return;
                }

                ExtractFile eFile = new ExtractFile(pkgPath);
                eFile.ExtractTo(pkgPath + ".info", 0);

                FileStream   infoFStream = new FileStream(pkgPath + ".info", FileMode.Open);
                StreamReader sReader     = new StreamReader(infoFStream);
                PBSetValue(25);

                double setValue = (double)60 / eFile.GetMaxFileCount();

                string line;
                int    i = 1;
                while ((line = sReader.ReadLine()) != null)
                {
                    eFile.ExtractTo(sInfo.path + line, i);
                    PBSetValue(progressBar.Value + setValue);
                    i++;
                }
                sReader.Close();
                fStream.Close();

                File.Delete(pkgPath);
                File.Delete(pkgPath + ".info");

                //Register software information.
                RegistryKey key      = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", true);
                RegistryKey software = key.CreateSubKey("LiteQnaire");

                software.SetValue("DisplayIcon", sInfo.path + @"\LiteQnaire\LiteQnaire.exe");
                software.SetValue("DisplayName", "LiteQnaire Set");
                software.SetValue("DisplayVersion", "1.0");
                software.SetValue("Publisher", "Nekorokke");
                software.SetValue("InstallLocation", sInfo.path);
                software.SetValue("InstallSource", sInfo.path);

                software.SetValue("UninstallString", sInfo.path + "\\uninstall.exe");
                software.Close();
                key.Close();
                PBSetValue(90);

                //Register file association.
                if (sInfo.open == true)
                {
                    key = Registry.ClassesRoot.CreateSubKey(".lqn");
                    key.SetValue("", "LiteQnaire.LQN");
                    key = Registry.ClassesRoot.CreateSubKey("LiteQnaire.LQN\\Shell\\Open\\Command");
                    key.SetValue("", "\"" + sInfo.path + "LiteQnaire\\LiteQnaire.exe\"" + "\" %1\"");

                    key = Registry.ClassesRoot.CreateSubKey("LiteQnaire.LQN\\DefaultIcon");
                    key.SetValue("", sInfo.path + "LiteQnaire\\lqnfile.ico");
                    key.Close();
                }
                PBSetValue(93);

                //Register 'Edit with LiteQnaire Editor' command menu.
                if (sInfo.edit == true)
                {
                    key = Registry.ClassesRoot.CreateSubKey("LiteQnaire.LQN\\Shell\\Edit");
                    key.SetValue("", "Edit with LiteQnaire Editor");
                    key = Registry.ClassesRoot.CreateSubKey("LiteQnaire.LQN\\Shell\\Edit\\Command");
                    key.SetValue("", "\"" + sInfo.path + "LiteQnaire Editor\\LiteQnaire Editor.exe\"" + "\" %1\"");
                    key.Close();
                }
                PBSetValue(95);

                //Create shortcut.
                if (sInfo.scDestop == true)
                {
                    string desktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);

                    WSH.WshShell     wshShell = new WSH.WshShell();
                    WSH.IWshShortcut shortcut = (WSH.IWshShortcut)wshShell.CreateShortcut(desktopPath + "\\LiteQnaire Reader.lnk");
                    shortcut.TargetPath   = sInfo.path + "LiteQnaire\\LiteQnaire.exe";
                    shortcut.IconLocation = sInfo.path + "LiteQnaire\\LiteQnaire.exe,0";
                    shortcut.Description  = "LiteQnaire Reader";
                    shortcut.Save();

                    shortcut              = (WSH.IWshShortcut)wshShell.CreateShortcut(desktopPath + "\\LiteQnaire Editor.lnk");
                    shortcut.TargetPath   = sInfo.path + "LiteQnaire Editor\\LiteQnaire Editor.exe";
                    shortcut.IconLocation = sInfo.path + "LiteQnaire Editor\\LiteQnaire Editor.exe,0";
                    shortcut.Description  = "LiteQnaire Editor";
                    shortcut.Save();

                    shortcut              = (WSH.IWshShortcut)wshShell.CreateShortcut(desktopPath + "\\LiteQnaire Collector.lnk");
                    shortcut.TargetPath   = sInfo.path + "LiteQnaire Collector\\LiteQnaire Collector.exe";
                    shortcut.IconLocation = sInfo.path + "LiteQnaire Collector\\LiteQnaire Collector.exe,0";
                    shortcut.Description  = "LiteQnaire Collector";
                    shortcut.Save();
                }
                PBSetValue(100);

                RefreshDesktop.Refresh();

                startnowBorder.Visibility = Visibility.Visible;
                MessageBox.Show("LiteQnaire Successfully Installed!", "LiteQnaire Setup", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message + "\r\nInstall Failed.Please try again.", "LiteQnaire Setup", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    private void addStartup_CheckedChanged(object sender, EventArgs e)
    {
        Logger.Debug("call:addStartup_CheckedChanged");
        if (addStartup.Checked)
        {
            Logger.Debug(true);
            //スタートアップ登録
            //ショートカットの作成
            string shortcutPath = System.IO.Path.Combine(Environment.GetFolderPath(System.Environment.SpecialFolder.Startup), @"MinecraftAutoBackup.lnk");
            // ショートカットのリンク先(起動するプログラムのパス)
            string targetPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\SubModule\\MABProcessAtWait";
            Logger.Debug($"{targetPath}へのショートカットを{shortcutPath}に作成します");

            // WshShellを作成
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
            // ショートカットのパスを指定して、WshShortcutを作成
            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);
            // ①リンク先
            shortcut.TargetPath = targetPath;
            // ②引数
            shortcut.Arguments = "";
            // ③作業フォルダ
            shortcut.WorkingDirectory = Application.StartupPath;
            // ④実行時の大きさ 1が通常、3が最大化、7が最小化
            shortcut.WindowStyle = 1;
            // ⑤コメント
            shortcut.Description = "MABProcessへのショートカットです。";
            // ⑥アイコンのパス 自分のEXEファイルのインデックス0のアイコン
            shortcut.IconLocation = Application.ExecutablePath + ",0";

            // ショートカットを作成
            shortcut.Save();

            // 後始末
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell);

            if (File.Exists(shortcutPath))
            {
                MessageBox.Show(
                    "スタートアップに登録しました。\n\n",
                    "MABProcessAtWait",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(
                    "スタートアップへの登録に失敗しました。\n\n",
                    "MABProcessAtWait",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
            }
        }
        else
        {
            Logger.Debug(false);
            //解除
            Logger.Debug($"{Environment.GetFolderPath(System.Environment.SpecialFolder.Startup)}\\MinecraftAutoBackup.lnkを削除します");
            File.Delete($"{Environment.GetFolderPath(System.Environment.SpecialFolder.Startup)}\\MinecraftAutoBackup.lnk");
        }
    }
示例#24
0
        /// <summary>
        /// Create Shortcut
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreate_Click(object sender, EventArgs e)
        {
            TargetPath       = "";
            WorkingDirectory = "";
            Description      = "";
            Arguments        = "";
            Hotkey           = "";
            IconLocation     = "";

            if (string.IsNullOrEmpty(this.tbPath.Text.Trim()))
            {
                Msg("未选择文件", MSG_TYPE.ERROR);
                return;
            }
            if (!this.cbDesktop.Checked && !this.cbStartMenu.Checked)
            {
                Msg("未选择快捷方式类型", MSG_TYPE.ERROR);
                return;
            }

            if (this.cmbShutcuts.SelectedIndex > -1)
            {
                if (this.cbCtrl.Checked || this.cbShift.Checked || this.cbAlt.Checked)
                {
                    Hotkey += this.cbCtrl.Checked ? "CTRL+" : "";
                    Hotkey += this.cbShift.Checked ? "SHIFT+" : "";
                    Hotkey += this.cbAlt.Checked ? "ALT+" : "";
                    Hotkey += this.cmbShutcuts.Text;
                }
            }

            TargetPath = this.tbPath.Text.Trim();

            FullName         = this.tbFullName.Text.Trim();
            WorkingDirectory = TargetPath.Replace(@"\" + FullName + ".exe", "");
            Description      = this.rtbDescription.Text.Trim();
            Arguments        = this.tbArguments.Text.Trim();
            IconLocation     = string.Format("{0},0", TargetPath);//icon

            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

            //Desktop
            if (this.cbDesktop.Checked)
            {
                string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
                IWshRuntimeLibrary.IWshShortcut Desktop = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + string.Format(@"\{0}.lnk", FullName));

                Desktop.TargetPath       = TargetPath;
                Desktop.Arguments        = Arguments;
                Desktop.Description      = Description;
                Desktop.WorkingDirectory = WorkingDirectory;
                Desktop.IconLocation     = IconLocation;
                Desktop.Hotkey           = Hotkey;
                Desktop.WindowStyle      = 1;
                Desktop.Save();
                Msg("创建快捷方式完成", MSG_TYPE.GREEN);
            }

            if (this.cbStartMenu.Checked)
            {
                //StartMenu
                string StartMenuPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu);
                IWshRuntimeLibrary.IWshShortcut StartMenu = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(StartMenuPath + string.Format(@"\{0}.lnk", FullName));

                StartMenu.TargetPath       = TargetPath;
                StartMenu.Arguments        = Arguments;
                StartMenu.Description      = Description;
                StartMenu.WorkingDirectory = WorkingDirectory;
                StartMenu.IconLocation     = IconLocation;
                StartMenu.Hotkey           = Hotkey;
                StartMenu.WindowStyle      = 1;
                StartMenu.Save();
                Msg("创建快捷方式完成", MSG_TYPE.GREEN);
            }
        }
示例#25
0
文件: Program.cs 项目: liujf5566/Tool
 /// <summary>
 /// 创建快捷键
 /// </summary>
 /// <param name="pathLink">快捷键路径</param>
 /// <param name="shortcutName">快捷方式名称</param>
 /// <param name="appName">应用</param>
 /// <param name="ico">图标</param>
 static void CreateLink(string pathLink, string shortcutName, string appName, string ico)
 {
     try
     {
         pathLink = Path.Combine(pathLink, shortcutName + ".lnk");
         //如果存在快捷键,先删除
         if (File.Exists(pathLink))
         {
             File.Delete(pathLink);
         }
         SHORT.WshShell shell = new SHORT.WshShell();
         SHORT.IWshShortcut shortcut = shell.CreateShortcut(pathLink);
         shortcut.TargetPath = Path.Combine(_rootDir, appName);
         shortcut.WorkingDirectory = _rootDir;
         shortcut.Description = shortcutName;
         shortcut.IconLocation = ico;
         shortcut.WindowStyle = 1;
         shortcut.Save();
     }
     catch (Exception)
     {
         throw;
     }
 }