コード例 #1
0
ファイル: Shortcut.cs プロジェクト: road0001/TileBeautify
        //创建或重建快捷方式
        public void CreateShortcut(string exePath, string tileName, string iconPath, int iconIndex, bool isUrl)
        {
            var  wsh             = new IWshRuntimeLibrary.WshShell();
            bool isAlreadyHasLnk = IsAlreadyHasLnk(exePath, out var lnkPathList);

            if (isAlreadyHasLnk)
            {
                foreach (var lnkPath in lnkPathList)
                {
                    var    shortcut         = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(lnkPath);
                    string newLnkPath       = Path.GetDirectoryName(lnkPath) + "\\" + tileName + ".lnk";
                    string targetPath       = shortcut.TargetPath;       //目标位置
                    string arguments        = shortcut.Arguments;        //目标参数
                    string workingDirectory = shortcut.WorkingDirectory; //工作目录
                    string description      = shortcut.Description;      //备注
                    string hotkey           = shortcut.Hotkey;           //快捷键
                    int    windowStyle      = shortcut.WindowStyle;      //运行方式
                    File.Delete(lnkPath);

                    shortcut                  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(newLnkPath);
                    shortcut.TargetPath       = targetPath;
                    shortcut.Arguments        = arguments;
                    shortcut.WorkingDirectory = workingDirectory;
                    shortcut.Description      = description;
                    shortcut.Hotkey           = hotkey;
                    shortcut.WindowStyle      = windowStyle;
                    shortcut.IconLocation     = iconPath + "," + iconIndex.ToString();
                    shortcut.Save();
                }
            }
            else
            {
                string folder;
                if (isUrl == true)
                {
                    folder = FormEditConfig.StartMenuUrl;
                }
                else
                {
                    folder = FormEditConfig.StartMenuExe;
                }
                Directory.CreateDirectory(folder);
                string newLnkPath = folder + tileName + ".lnk";
                var    shortcut   = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(newLnkPath);
                shortcut.TargetPath       = exePath;
                shortcut.WorkingDirectory = Path.GetDirectoryName(exePath);
                shortcut.WindowStyle      = 1;
                shortcut.IconLocation     = iconPath + "," + iconIndex.ToString();
                shortcut.Save();
            }
        }
コード例 #2
0
        //https://stackoverflow.com/questions/5089601/how-to-run-a-c-sharp-application-at-windows-startup
        //Since question is WPF related, notice that Application.ExecutablePath is part of System.Windows.Forms, and will result in cannot resolve symbol in WPF project. You can use System.Reflection.Assembly.GetExecutingAssembly().Location as proper replacement. – itsho Feb 22 '15 at 7:024
        //Assembly.GetExecutingAssembly() will get the assembly currently running the code.It will not get the correct assembly if the code is executed on another assembly. Use Assembly.GetEntryAssembly() instead.
        private void RegisterInStartup(bool isChecked)
        {
            //shell:startup

            if (isChecked)
            {
                //create shortcut to file in startup
                IWshRuntimeLibrary.WshShell     wsh      = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
                    Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ClipboardMonitor.lnk") as IWshRuntimeLibrary.IWshShortcut;
                shortcut.Arguments        = "";
                shortcut.TargetPath       = Environment.CurrentDirectory + @"\ClipboardMonitor.exe";
                shortcut.WindowStyle      = 1;
                shortcut.Description      = "Clipboard Monitor";
                shortcut.WorkingDirectory = Environment.CurrentDirectory + @"\";
                //shortcut.IconLocation = @"clipboard.ico";
                shortcut.Save();
            }
            else
            {
                if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ClipboardMonitor.lnk"))
                {
                    File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\ClipboardMonitor.lnk");
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// This method extracts the target file path from the spetified shortcut (*.lnk) file path
        /// </summary>
        /// <param name="shortcutPath">The path ro the shortcut file</param>
        /// <returns>Target file path of the shortcut</returns>
        private static string GetShortcutTargetFile(string shortcutPath)
        {
            IWshRuntimeLibrary.WshShell     shell = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut link  = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);

            return(link.TargetPath);
        }
コード例 #4
0
 public static void Main(string[] args)
 {
     if (!Properties.Settings.Default.SendToCreated)//If not initialized create a shortcut in the sendto
     {
         string sendToFolder = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
         string filename     = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);
         string execPath     = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
         IWshRuntimeLibrary.WshShell     shell = new IWshRuntimeLibrary.WshShell();
         IWshRuntimeLibrary.IWshShortcut link  = (IWshRuntimeLibrary.IWshShortcut)
                                                 shell.CreateShortcut(Path.Combine(sendToFolder, filename + ".lnk"));
         link.TargetPath = Path.Combine(execPath, filename + ".exe");
         link.Save();
         Properties.Settings.Default.SendToCreated = true;
         Properties.Settings.Default.Save();
     }
     Console.WriteLine("Started DicomFile Opener");
     if (args.Length > 0)
     {
         foreach (string arg in args)
         {
             PrintFile(arg);
         }
     }
     else
     {
         Console.WriteLine("Enter a file path:");
         string file = Console.ReadLine();
         PrintFile(file);
     }
     Console.WriteLine("Press the any-key to continue");
     Console.ReadLine();
 }
コード例 #5
0
        //获取文件真实路径
        private static string GetRealPath(string filePath)
        {
            string format = Path.GetExtension(filePath).ToLower();

            if (format == ".exe")
            {
                return(filePath);
            }
            else if (format == ".lnk")
            {
                var wsh      = new IWshRuntimeLibrary.WshShell();
                var shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(filePath);
                filePath = shortcut.TargetPath;
                if (!File.Exists(filePath))
                {
                    MessageBox.Show("此快捷方式指向的文件路径不存在" + "\n" + "或者为不支持修改样式的UWP应用", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }
                format = Path.GetExtension(filePath).ToLower();
                if (format == ".exe")
                {
                    return(filePath);
                }
                else
                {
                    MessageBox.Show("这不是exe程序的快捷方式", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: IOHelpers.cs プロジェクト: mingslogar/dimension4
        public static string GetLinkTarget(string link)
        {
            IWshRuntimeLibrary.IWshShell    wsh = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(link);

            return(sc.TargetPath);
        }
コード例 #7
0
ファイル: AppInfoLink.cs プロジェクト: uta666666/AppTray
        private IWshRuntimeLibrary.IWshShortcut LoadLink(string filePath)
        {
            var shell       = new IWshRuntimeLibrary.WshShell();
            var objShortcut = shell.CreateShortcut(filePath) as IWshRuntimeLibrary.IWshShortcut;

            return(objShortcut);
        }
コード例 #8
0
        private void BtnAddStartMenu_Click(object sender, EventArgs e)
        {
            //作成するショートカットのパス
            var shortcutPath = StartMenuShortcutPath;

            // フォルダを作成
            Directory.CreateDirectory(Path.GetDirectoryName(shortcutPath));

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

            //リンク先
            shortcut.TargetPath = Application.ExecutablePath;
            //コマンドパラメータ 「リンク先」の後ろに付く
            shortcut.Arguments = @"unspecified """ + SSPDirPath + @"""";
            //作業フォルダ
            shortcut.WorkingDirectory = Application.StartupPath;
            //コメント
            shortcut.Description = "テストのアプリケーション";
            //アイコンのパス 自分のEXEファイルのインデックス0のアイコン
            shortcut.IconLocation = Application.ExecutablePath + ",1";

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

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

            UpdateUIState();

            MessageBox.Show("スタートメニューに登録しました。", "情報", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #9
0
        public PathConfig(string exePath)
        {
            BtsExePath = exePath;

            var info = new FileInfo(BtsExePath);

            if (!info.Exists)
            {
                return;
            }

            var dirMods = info.Directory.GetDirectories("MODS");

            if (dirMods.Length == 1)
            {
                BtsModsPath = dirMods[0].FullName;
            }

            var usersModsLnks = info.Directory.GetFiles("_Civ4CustomMods.lnk");

            if (usersModsLnks.Length == 1)
            {
                // ショートカットを辿る
                var shell    = new IWshRuntimeLibrary.WshShell();
                var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(usersModsLnks[0].FullName);
                UsersModsPath = shortcut.TargetPath.ToString();
            }
        }
コード例 #10
0
        private void createStartupButton_Click(object sender, EventArgs e)
        {
            if (File.Exists(shortcutPath))
            {
                if (MessageBox.Show(Properties.Resources.MessageStartupOverwrite, AppUtil.GetAppName(), MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }
            }

            IWshRuntimeLibrary.WshShell     shell    = null;
            IWshRuntimeLibrary.IWshShortcut shortcut = null;
            try
            {
                shell                     = new IWshRuntimeLibrary.WshShell();
                shortcut                  = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);
                shortcut.TargetPath       = Application.ExecutablePath;
                shortcut.WorkingDirectory = Application.StartupPath;
                shortcut.Save();
                MessageBox.Show(Properties.Resources.MessageStartupCreated, AppUtil.GetAppName());
            }
            finally
            {
                if (shortcut != null)
                {
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shortcut);
                }
                if (shell != null)
                {
                    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell);
                }
            }
        }
コード例 #11
0
ファイル: ShortcutsProvider.cs プロジェクト: senpost/Shortie
 public static FileInfo GetTargetFileInfo(string shortcutPath)
 {
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
     var link = shell.CreateShortcut(shortcutPath);
     var targetFileInfo = new FileInfo(link.TargetPath as string);
     return targetFileInfo;
 }
コード例 #12
0
 /// <summary>
 /// Sets up the startup link for the app.
 /// </summary>
 private void StartupSetup()
 {
     try
     {
         if (settings.runOnStartup && !File.Exists(linkPath)) // If run on startup is enabled and the link isn't in the Startup folder
         {
             IWshRuntimeLibrary.WshShell     wsh      = new IWshRuntimeLibrary.WshShell();
             IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(linkPath) as IWshRuntimeLibrary.IWshShortcut;
             shortcut.Description      = "Discord Custom Rich Presence Manager";
             shortcut.TargetPath       = Environment.CurrentDirectory + @"\CustomRP.exe";
             shortcut.WorkingDirectory = Environment.CurrentDirectory + @"\";
             shortcut.Save();
         }
         else if (!settings.runOnStartup && File.Exists(linkPath)) // If run on startup is disabled and the link is in the Startup folder
         {
             File.Delete(linkPath);
         }
     }
     catch (Exception e)
     {
         // I *think* this would only happen if an antivirus would intervene saving/deleting a file in a user folder,
         // therefore I'm just allowing the user to quickly try changing the option again
         runOnStartupToolStripMenuItem.Checked = !settings.runOnStartup;
         MessageBox.Show(e.Message, Strings.error, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #13
0
ファイル: Program.cs プロジェクト: xmxth001/OutlookGoogleSync
        public static void AddShortcut(Environment.SpecialFolder directory, String subdir = "")
        {
            log.Debug("AddShortcut: directory=" + directory.ToString() + "; subdir=" + subdir);
            String appPath = Application.ExecutablePath;

            if (subdir != "")
            {
                subdir = "\\" + subdir;
            }
            String shortcutDir = Environment.GetFolderPath(directory) + subdir;

            if (!System.IO.Directory.Exists(shortcutDir))
            {
                log.Debug("Creating directory " + shortcutDir);
                System.IO.Directory.CreateDirectory(shortcutDir);
            }

            string shortcutLocation = System.IO.Path.Combine(shortcutDir, "OutlookGoogleCalendarSync.lnk");

            IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(shortcutLocation) as IWshRuntimeLibrary.WshShortcut;

            shortcut.Description      = "Synchronise Outlook and Google calendars";
            shortcut.IconLocation     = appPath.ToLower().Replace("OutlookGoogleCalendarSync.exe", "icon.ico");
            shortcut.TargetPath       = appPath;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Save();
            log.Info("Created shortcut in \"" + shortcutDir + "\"");
        }
コード例 #14
0
        public static void EnforceConfiguration()
        {
            string FilePath      = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
            string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            string shortcutName  = AppDomain.CurrentDomain.FriendlyName + ".lnk";
            string shortcutPath  = Path.Combine(startupFolder, shortcutName);

            string existingShortcut = FindExistingShortcut(startupFolder, FilePath);

            if (Global.Configuration.AutoStart) //Create the link
            {
                if (string.IsNullOrEmpty(existingShortcut))
                {
                    try {
                        var shell    = new IWshRuntimeLibrary.WshShell();
                        var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);
                        shortcut.TargetPath = FilePath;                 // The path of the file that will launch when the shortcut is run
                        shortcut.Save();
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message); }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(existingShortcut))
                {
                    try { File.Delete(existingShortcut); }
                    catch (Exception ex) { MessageBox.Show(ex.Message); }
                }
            }
        }
コード例 #15
0
        //获取文件真实路径
        private static string GetRealPath(string filePath)
        {
            string format = Path.GetExtension(filePath).ToLower();

            if (format == ".exe")
            {
                return(filePath);
            }
            else if (format == ".lnk")
            {
                var wsh      = new IWshRuntimeLibrary.WshShell();
                var shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(filePath);
                filePath = shortcut.TargetPath;
                if (!File.Exists(filePath))
                {
                    new FormMyMessageBox("此快捷方式指向的文件路径不存在\n或者为不支持修改样式的UWP应用").Show();
                    return(null);
                }
                format = Path.GetExtension(filePath).ToLower();
                if (format == ".exe")
                {
                    return(filePath);
                }
                else
                {
                    new FormMyMessageBox("这不是exe程序的快捷方式").Show();
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #16
0
ファイル: Cache.cs プロジェクト: StarsCreator/Saturnus
        private void LoadStartMenu(string path)
        {
            var shell = new IWshRuntimeLibrary.WshShell();

            try
            {
                //var files = Directory.GetFiles(path);

                foreach (var file in Directory.GetFiles(path))
                {
                    var fileinfo = new FileInfo(file);

                    if (fileinfo.Extension.ToLower() != ".lnk")
                    {
                        continue;
                    }
                    var link = shell.CreateShortcut(file) as IWshRuntimeLibrary.WshShortcut;
                    var sr   = new Result(fileinfo.Name.Substring(0, fileinfo.Name.Length - 4),
                                          link.TargetPath, file, Execute);
                    _cachedItems.Add(sr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                foreach (var dir in Directory.GetDirectories(path))
                {
                    LoadStartMenu(dir);
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// 开机自动启动
        /// 赋值快捷方式到[启动]文件夹
        /// </summary>
        /// <returns>开启或停用是否成功</returns>
        public static void SetSelfStart()
        {
            // 先确保有操作权限
            AppElvatedHelper.ElvateApp(StartupMode.SetSelfStart);
            try
            {
                var startUpPath  = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartup);
                var shortcutPath = System.IO.Path.Combine(startUpPath, string.Format("{0}.lnk", "上班统计"));
                //string shortcutPath = Process.GetCurrentProcess().MainModule.FileName + ".lnk";//System.IO.Path.Combine(startUpPath, string.Format("{0}.lnk", "上班统计"));

                var exePath = Process.GetCurrentProcess().MainModule.FileName;
                if (File.Exists(shortcutPath))
                {
                    File.Delete(shortcutPath);
                }
                var shell    = new IWshRuntimeLibrary.WshShell();
                var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);
                shortcut.TargetPath       = exePath;                                   // exe路径
                shortcut.Arguments        = "1";                                       // 启动参数
                shortcut.IconLocation     = exePath;
                shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(exePath);; //软件所在文件夹
                shortcut.Description      = "上班统计";
                shortcut.Save();
                MessageBox.Show("已在启动文件夹内创建快捷方式。");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #18
0
ファイル: Cache.cs プロジェクト: StarsCreator/Saturnus
        private void LoadStartMenu(string path)
        {
            var shell = new IWshRuntimeLibrary.WshShell();

            try
            {
                //var files = Directory.GetFiles(path);

                foreach (var file in Directory.GetFiles(path))
                {
                    var fileinfo = new FileInfo(file);

                    if (fileinfo.Extension.ToLower() != ".lnk") continue;
                    var link = shell.CreateShortcut(file) as IWshRuntimeLibrary.WshShortcut;
                    var sr = new Result(fileinfo.Name.Substring(0, fileinfo.Name.Length - 4),
                        link.TargetPath, file,Execute);
                    _cachedItems.Add(sr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {

                foreach (var dir in Directory.GetDirectories(path))
                {
                    LoadStartMenu(dir);
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Creates a new Windows shortcut.
        /// </summary>
        /// <param name="path">The location to place the shorcut at.</param>
        /// <param name="targetPath">The target path the shortcut shall point to.</param>
        /// <param name="arguments">Additional arguments to pass to the target; can be <c>null</c>.</param>
        /// <param name="iconLocation">The path of the icon to use for the shortcut; leave <c>null</c> ot get the icon from <paramref name="targetPath"/>.</param>
        /// <param name="description">A short human-readable description; can be <c>null</c>.</param>
        public static void Create([NotNull] string path, [NotNull] string targetPath, [CanBeNull] string arguments = null, [CanBeNull] string iconLocation = null, [CanBeNull] string description = null)
        {
#if !__MonoCS__
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            var wshShell = new IWshRuntimeLibrary.WshShell();
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(path);

            shortcut.TargetPath = targetPath;
            if (!string.IsNullOrEmpty(arguments))
            {
                shortcut.Arguments = arguments;
            }
            if (!string.IsNullOrEmpty(iconLocation))
            {
                shortcut.IconLocation = iconLocation;
            }
            if (!string.IsNullOrEmpty(description))
            {
                shortcut.Description = description.Substring(0, Math.Min(description.Length, 256));
            }

            shortcut.Save();
#endif
        }
コード例 #20
0
ファイル: FrmConfig.cs プロジェクト: krank/bsgl
        /// <summary>
        /// Creates a desktop shortcut to launch the game
        /// </summary>
        /// <param name="game">The <see cref="Game"/> to create shortcut for</param>
        protected internal virtual void CreateDesktopShortcut(Game game)
        {
            var app        = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var linkName   = Game.RemoveIllegalCharsFromFileName(game.Title);
            var linkPath   = Path.Combine(desktopDir, linkName);

            #if WIN_32
            linkPath += ".lnk";
            var shell    = new IWshRuntimeLibrary.WshShell();
            var shortcut = shell.CreateShortcut(linkPath) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.TargetPath       = app;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Arguments        = game.Id.ToString();
            shortcut.IconLocation     = game.Path.Replace('\\', '/');
            shortcut.Save();
            #elif LINUX
            linkPath += ".desktop";
            using (StreamWriter file = new StreamWriter(linkPath, false))
            {
                file.WriteLine("[Desktop Entry]");
                file.WriteLine("Type=Application");
                file.WriteLine("Name={0}", game.Title);
                file.WriteLine("Comment=Generated by bsgl");
                file.WriteLine("Exec=mono {0} {1}", app, game.Id.ToString());
                file.WriteLine("Icon={0}", game.Title);
            }
            #else
            MessageBox.Show("Creation of desktop shortcuts is not supported on this platform.",
                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            #endif
        }
コード例 #21
0
ファイル: FileDialogModel.cs プロジェクト: CDW90/dataforest
        public FileDialogModel()
        {
            string links = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Links");
            DirectoryInfo fav = new DirectoryInfo(links);
            Favorites.Add(new MyComputer{ Name = "Computer" });
            if (fav.Exists)
            {
                IWshRuntimeLibrary.IWshShell shell = new IWshRuntimeLibrary.WshShell();
                foreach (FileInfo lnk in fav.GetFiles("*.lnk", SearchOption.TopDirectoryOnly))
                {
                    string path = ((IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(lnk.FullName)).TargetPath;
                    if (!String.IsNullOrEmpty(path))
                    {
                        DirectoryInfo directory = new DirectoryInfo(path);
                        if (directory.Exists)
                        {
                            Favorites.Add(directory);
                        }
                    }
                }

            }

            this.Filters = "Alle |*";
            this.SelectedFilter = filters.FirstOrDefault();

            if (startDirectory != null)
            {
                CurrentDirectory = new DirectoryInfo(startDirectory);
            }
            else
            {
                CurrentDirectory = null;
            }
        }
コード例 #22
0
ファイル: Program.cs プロジェクト: lewisjaggi/Security
 static void CreateShortcut(string fileName)
 {
     IWshRuntimeLibrary.WshShell     wsh      = new IWshRuntimeLibrary.WshShell();
     IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
         Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\dropbox.lnk") as IWshRuntimeLibrary.IWshShortcut;
     shortcut.TargetPath = fileName;
     shortcut.Save();
 }
コード例 #23
0
        private string FindLauncherPath()
        {
            string launcherPath = null;

            // attempt 1. Read the registry
            RegistryKey key = null;

            try
            {
                if (Environment.Is64BitOperatingSystem)
                {
                    key = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Wow6432Node");
                }
                if (key == null)
                {
                    key = Registry.LocalMachine.OpenSubKey("SOFTWARE");
                }
                key = key.OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall");
                key = key.OpenSubKey("{696F8871-C91D-4CB1-825D-36BE18065575}_is1");

                if (key != null)
                {
                    launcherPath = key.GetValue("InstallLocation") as string;
                }
            }
            catch
            {
            }

            if (launcherPath != null)
            {
                return(launcherPath);
            }

            // attempt 2. try to read the shortcut in the program menu
            string menuPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs", "Frontier", "Elite Dangerous Launcher");
            string shortcut = Path.Combine(menuPath, "Elite Dangerous Launcher.lnk");

            if (File.Exists(shortcut))
            {
                var shell = new IWshRuntimeLibrary.WshShell();
                var lnk   = shell.CreateShortcut(shortcut);

                string launcherExePath = lnk.TargetPath;
                launcherPath = new FileInfo(launcherExePath).DirectoryName;
            }

            // attempt 3. try the default path
            if (launcherPath == null)
            {
                if (File.Exists(Path.Combine(DefLauncherPath, "EDLaunch.exe")))
                {
                    launcherPath = DefLauncherPath;
                }
            }

            return(launcherPath);
        }
コード例 #24
0
 private void NewMethod5(int c, int d)
 {
     IWshRuntimeLibrary.WshShell     shell = new IWshRuntimeLibrary.WshShell();
     IWshRuntimeLibrary.IWshShortcut link  = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(deskDir + "\\" + instOrdner[d] + ".lnk");
     link.IconLocation     = applicationPath + "\\" + instOrdner[d] + "\\msedge.exe" + "," + icon[c];
     link.WorkingDirectory = applicationPath;
     link.TargetPath       = applicationPath + "\\" + instOrdner[d] + " Launcher.exe";
     link.Save();
 }
コード例 #25
0
ファイル: StartupHelper.cs プロジェクト: noant/Pyrite
 public static void CreateStartupShortcut()
 {
     string shortcutLocation = ShortcutPath;
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutLocation);
     shortcut.Description = "Pyrite";
     shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
     shortcut.Save();
 }
コード例 #26
0
        private void ctlOK_Click(object sender, EventArgs e)
        {
            lock (Config.Instance.Lock)
            {
                if (Config.Instance.StartWithWindows != this.ctlAutoStartup.Checked)
                {
                    var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".lnk");

                    if (!Config.Instance.StartWithWindows)
                    {
                        try
                        {
                            var ws = new IWshRuntimeLibrary.WshShell();
                            IWshRuntimeLibrary.IWshShortcut shortCut = ws.CreateShortcut(path);

                            shortCut.Description = Lang.Name;
                            shortCut.TargetPath  = Application.ExecutablePath;
                            shortCut.Save();
                        }
                        catch (Exception ex)
                        {
                            SentrySdk.CaptureException(ex);
                        }
                    }
                    else
                    {
                        try
                        {
                            File.Delete(path);
                        }
                        catch (Exception ex)
                        {
                            SentrySdk.CaptureException(ex);
                        }
                    }
                }

                Config.Instance.StartWithWindows = this.ctlAutoStartup.Checked;

                Config.Instance.Proxy.Port = (int)this.ctlPort.Value;
                Config.Instance.Proxy.Id   = this.ctlAuthId.Text;
                Config.Instance.Proxy.Pw   = this.ctlAuthPw.Text;

                Config.Instance.ReduceApiCall = this.ctlReduceApiCall.Checked;

                Config.Instance.Filter.ShowRetweetedMyStatus  = this.ctlShowRetweet.Checked;
                Config.Instance.Filter.ShowRetweetWithComment = this.ctlShowRetweetWithComment.Checked;
                Config.Instance.Filter.ShowMyRetweet          = this.ctlShowMyRetweet.Checked;

                Config.Instance.EnableDnsPatch = this.ctlDnsPatch.Checked;
            }

            Config.Save();

            this.Close();
        }
コード例 #27
0
        private void createInstallerShortcut()
        {
            string installerDirectory = PathManager.GetInstallerFilesDirectory(this.RollOutDirectory);

            IWshRuntimeLibrary.WshShell     wsh      = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(this.RollOutDirectory + "Front End Installer.lnk");
            shortcut.TargetPath       = installerDirectory + "\\AccessLauncher.FrontEndInstaller.exe";
            shortcut.WorkingDirectory = installerDirectory.Substring(0, installerDirectory.Length - 1);
            shortcut.Save();
        }
コード例 #28
0
        static void CreateShortcut(string shortcutAddress, string targetPath, string arguments, string iconPath)
        {
            var shell    = new IWshRuntimeLibrary.WshShell();
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress);

            shortcut.TargetPath   = targetPath;
            shortcut.Arguments    = arguments;
            shortcut.IconLocation = iconPath;
            shortcut.Save();
        }
コード例 #29
0
 static void CreateShortcut(string basePath, string name, string targetPath)
 {
     try
     {
         var shell           = new IWshRuntimeLibrary.WshShell();
         var shortcutAddress = @$ "{basePath}\{name}.lnk";
         var shortcut        = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress);
         shortcut.Description = $"Shortcut to {name}";
         shortcut.TargetPath  = targetPath;
         shortcut.Save();
     }
コード例 #30
0
        private void CreateShortcut()
        {
            var shell      = new IWshRuntimeLibrary.WshShell();
            var shorcutObj = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(ShortcutPath);

            shorcutObj.TargetPath = ApplicationPath;
            shorcutObj.Save();

            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shorcutObj);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(shell);
        }
コード例 #31
0
        private static void createDesktopShortcut()
        {
            string appDataPath = Domain.FrontEnd.GetInfo.GetAppDataPath();

            IWshRuntimeLibrary.WshShell     wsh      = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\PB Database.lnk");
            shortcut.TargetPath       = appDataPath + "AccessLauncher.FrontEnd.exe";
            shortcut.WorkingDirectory = appDataPath;
            shortcut.IconLocation     = appDataPath + "p_b_blue.ico";
            shortcut.Save();
        }
コード例 #32
0
        public static void CreateStartMenuShortcut(string linkedFileLocation, string linkedFileName)
        {
            IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut shortcut =
                (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(
                                                                          Environment.SpecialFolder.StartMenu) + "\\" + linkedFileName);

            shortcut.Description = "Shortcut for main application";
            shortcut.TargetPath  = linkedFileLocation + linkedFileName;
            shortcut.Save();
        }
コード例 #33
0
ファイル: Programs.cs プロジェクト: xuze1993/Playnite
        public static void CreateShortcut(string executablePath, string arguments, string iconPath, string shortcutPath)
        {
            var shell = new IWshRuntimeLibrary.WshShell();
            var link  = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);

            link.TargetPath       = executablePath;
            link.WorkingDirectory = Path.GetDirectoryName(executablePath);
            link.Arguments        = arguments;
            link.IconLocation     = string.IsNullOrEmpty(iconPath) ? executablePath + ",0" : iconPath;
            link.Save();
        }
コード例 #34
0
        /// <summary>
        /// Method to create shortcut file in destination.
        /// </summary>
        /// <param name="source">Source file path.</param>
        /// <param name="destination">Destination file path.</param>
        private static void CreateShortcut(string source, string destination)
        {
            File.Delete(destination);
            var shell    = new IWshRuntimeLibrary.WshShell();
            var shortcut = shell.CreateShortcut(destination) as IWshRuntimeLibrary.IWshShortcut;

            shortcut.TargetPath       = source;
            shortcut.WorkingDirectory = source;
            shortcut.Description      = "Cyberoam Auth Manager";
            shortcut.Save();
        }
コード例 #35
0
ファイル: ShortcutsProvider.cs プロジェクト: senpost/Shortie
        internal void CreateShortcut(string path)
        {
            FileInfo fileInfo = new FileInfo(path);
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
            string shortcurtFilePath = Path.Combine(shortcutFolder, fileInfo.Name+ ".lnk");

            if (File.Exists(shortcurtFilePath))
                Far.Net.Message("Shortcut already exist");
            var link = shell.CreateShortcut(shortcurtFilePath);
            link.TargetPath = fileInfo.FullName;
            link.Save();
        }
コード例 #36
0
ファイル: DemoFiler.cs プロジェクト: senpost/Shortie
 public override void Invoke(object sender, ModuleFilerEventArgs e)
 {
     try
     {
         IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
         var link = shell.CreateShortcut(e.Name);
         var targetFileInfo = new FileInfo(link.TargetPath as string);
         ShortieCommand.ProcessShortcut(targetFileInfo);
     }
     catch
     {
         //TODO Senthil
     }
 }
コード例 #37
0
ファイル: Shortcut.cs プロジェクト: 0install/0install-win
        /// <summary>
        /// Creates a new Windows shortcut.
        /// </summary>
        /// <param name="path">The location to place the shorcut at.</param>
        /// <param name="targetPath">The target path the shortcut shall point to.</param>
        /// <param name="arguments">Additional arguments to pass to the target; can be <c>null</c>.</param>
        /// <param name="iconLocation">The path of the icon to use for the shortcut; leave <c>null</c> ot get the icon from <paramref name="targetPath"/>.</param>
        /// <param name="description">A short human-readable description; can be <c>null</c>.</param>
        public static void Create([NotNull] string path, [NotNull] string targetPath, [CanBeNull] string arguments = null, [CanBeNull] string iconLocation = null, [CanBeNull] string description = null)
        {
#if !__MonoCS__
            if (File.Exists(path)) File.Delete(path);

            var wshShell = new IWshRuntimeLibrary.WshShell();
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(path);

            shortcut.TargetPath = targetPath;
            if (!string.IsNullOrEmpty(arguments)) shortcut.Arguments = arguments;
            if (!string.IsNullOrEmpty(iconLocation)) shortcut.IconLocation = iconLocation;
            if (!string.IsNullOrEmpty(description)) shortcut.Description = description.Substring(0, Math.Min(description.Length, 256));

            shortcut.Save();
#endif
        }
コード例 #38
0
        public string ResolveShortcut(string filePath)
        {
            // IWshRuntimeLibrary is in the COM library "Windows Script Host Object Model"
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
 
            try
            {
                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
                return shortcut.TargetPath;
            }
            catch (COMException)
            {
                // A COMException is thrown if the file is not a valid shortcut (.lnk) file 
                return null;
            }
        }
コード例 #39
0
        static App analyseFile(string fileName)
        {
            if (fileName == null)
                return null;

            App app = new App();
            app.name = Path.GetFileNameWithoutExtension(fileName);
            app.cmd = fileName;
            return app;
            #if false
            if (Directory.Exists(fileName))
            {
                app.name = Path.GetFileName(fileName);
                app.cmd = "explorer " + fileName;
                return app;
            }
            if (!File.Exists(fileName))
            {
                return null;
            }

            string ext,name;
            do
            {
                ext = Path.GetExtension(fileName);
                name = Path.GetFileNameWithoutExtension(fileName);
                if(ext!=".lnk")
                    break;
                var shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut link=shell.CreateShortcut(fileName) as IWshRuntimeLibrary.IWshShortcut;
                fileName = link.TargetPath;
            }while (true);
            app.name = name;

            switch (ext)
            {
                case ".exe":
                    app.cmd = fileName;
                    break;
            }

            return app;
            #endif
        }
コード例 #40
0
ファイル: Form1.cs プロジェクト: Vinna/DeepInSummer
        private void button1_Click(object sender, EventArgs e)
        {
            string targetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "test.lnk");


            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(targetPath);
            shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
            shortcut.WindowStyle = 1;
            shortcut.Description = "test";
            shortcut.IconLocation = Path.Combine(System.Environment.SystemDirectory, "shell32.dll, 165");

            if (File.Exists(targetPath))
            {
                File.Delete(targetPath);
            }
            shortcut.Save();
        }
コード例 #41
0
ファイル: Program.cs プロジェクト: ksopyla/winmole
        private static void FindPorgrams(string basePath)
        {
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

            foreach (string file in System.IO.Directory.GetFiles(basePath))
            {
                System.IO.FileInfo fileinfo = new System.IO.FileInfo(file);

                if (fileinfo.Extension.ToLower() == ".lnk")
                {
                    IWshRuntimeLibrary.WshShortcut link = shell.CreateShortcut(file) as IWshRuntimeLibrary.WshShortcut;
                    DocProperties sr = new DocProperties(fileinfo.Name.Substring(0, fileinfo.Name.Length - 4), link.TargetPath, file);
                    StartPrograms.Add(sr);
                }
            }

            // recurse through the subfolders
            foreach (string dir in System.IO.Directory.GetDirectories(basePath))
            {
                FindPorgrams(dir);
            }
        }
コード例 #42
0
ファイル: Form1.cs プロジェクト: mrddos/planisphere
        private bool CreateDesktopIcons(string fileName, string linkName)
        {
            try
            {
                string p = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string s = this.GetBinFile(fileName);
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(p + "\\" + linkName + ".lnk");
                shortcut.TargetPath = s;
                shortcut.Arguments = "";
                shortcut.Description = fileName;
                shortcut.WorkingDirectory = Path.Combine(this.installPath.Text, this.binPath);
                shortcut.IconLocation = string.Format("{0},0", s);
                shortcut.Save();

                this.AddLog("桌面快捷方式创建成功");
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #43
0
ファイル: CreateForm.cs プロジェクト: SayHalou/ospy
        private void CreateSuggestions()
        {
            List<ApplicationListViewItem> items = new List<ApplicationListViewItem>();
            ImageList imageLst = new ImageList();
            imageLst.ColorDepth = ColorDepth.Depth32Bit;

            StringBuilder allUsersStartMenu = new StringBuilder(260 + 1);
            WinApi.SHGetSpecialFolderPath(IntPtr.Zero, allUsersStartMenu, WinApi.CSIDL.COMMON_PROGRAMS, false);

            Stack<DirectoryInfo> pendingDirs = new Stack<DirectoryInfo>();
            pendingDirs.Push(new DirectoryInfo(allUsersStartMenu.ToString()));
            pendingDirs.Push(new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)));

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

            while (pendingDirs.Count > 0)
            {
                DirectoryInfo dir = pendingDirs.Pop();

                try
                {
                    foreach (FileInfo file in dir.GetFiles("*.lnk"))
                    {
                        var shortcut = shell.CreateShortcut(file.FullName) as IWshRuntimeLibrary.IWshShortcut;
                        if (shortcut != null)
                        {
                            string name = Path.GetFileNameWithoutExtension(shortcut.FullName);
                            string targetName = Path.GetFileNameWithoutExtension(shortcut.TargetPath);
                            string targetExt = Path.GetExtension(shortcut.TargetPath);
                            if (targetExt == ".exe" && name.ToLower().IndexOf("uninst") < 0 && targetName.ToLower().IndexOf("uninst") < 0)
                            {
                                var item = new ApplicationListViewItem(name, shortcut.TargetPath, shortcut.Arguments, shortcut.WorkingDirectory);

                                var icon = System.Drawing.Icon.ExtractAssociatedIcon(item.FileName);
                                imageLst.Images.Add(item.FileName, icon);
                                item.ImageKey = item.FileName;

                                items.Add(item);
                            }
                        }
                    }

                    foreach (DirectoryInfo subdir in dir.GetDirectories())
                        pendingDirs.Push(subdir);
                }
                catch
                {
                }
            }

            items.Sort();

            suggestItems = items.ToArray();
            suggestImages = imageLst;

            searchBox.UpdateSuggestions(suggestItems, suggestImages);
        }
コード例 #44
0
ファイル: SearchingWindow.xaml.cs プロジェクト: elkine/MASGAU
        private void startMenuTraveller(string look_here)
        {
            if(backgroundWorker1.CancellationPending)
                return;

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

            try
            {
                foreach (FileInfo shortcut in new DirectoryInfo(look_here).GetFiles("*.lnk"))
                {
                    try {
                        link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcut.FullName);
                        if (link.TargetPath.Length >= game_path.Length && game_path.ToLower() == link.TargetPath.Substring(0, game_path.Length).ToLower())
                        {
                            this.outputFile(shortcut.FullName);
                            this.outputFileSystemPath(link.TargetPath);
                        }
                    } catch (Exception e) {
                        this.writeLine(e.Message);
                    }
                }
            } catch (FileNotFoundException e) {
            } catch (UnauthorizedAccessException e) {
            } catch (Exception e) {
                writeLine(e.Message);
            }

            try {
                foreach (DirectoryInfo now_here in new DirectoryInfo(look_here).GetDirectories())
                {
                    try {
                        startMenuTraveller(now_here.FullName);
                    } catch (Exception e) {
                        this.writeLine(e.Message);
                    }
                }
            } catch(DirectoryNotFoundException) {
            } catch(UnauthorizedAccessException) {
            } catch(Exception e) {
                writeLine(e.Message);
            }
        }
コード例 #45
0
        protected override DetectedLocations getPaths(LocationShortcut get_me)
        {
            FileInfo the_shortcut;
            //StringBuilder start_menu;
            DetectedLocations return_me = new DetectedLocations();
            String path;

            List<string> paths = this.getPaths(get_me.ev);
            the_shortcut = null;

            foreach (string check_me in paths) {
                the_shortcut = new FileInfo(Path.Combine(check_me, get_me.path));
                if (the_shortcut.Exists)
                    break;
            }

            if (the_shortcut != null && the_shortcut.Exists) {
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(the_shortcut.FullName);

                try {
                    path = Path.GetDirectoryName(link.TargetPath);
                    path = get_me.modifyPath(path);
                    return_me.AddRange(Core.locations.interpretPath(path));
                } catch { }
            }
            return return_me;
        }
コード例 #46
0
ファイル: Main.cs プロジェクト: BoudewijnGlas/Jackett
        private void CreateShortcut()
        {

            var appPath = Assembly.GetExecutingAssembly().Location;
            var shell = new IWshRuntimeLibrary.WshShell();
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(ShortcutPath);
            shortcut.Description = Assembly.GetExecutingAssembly().GetName().Name;
            shortcut.TargetPath = appPath;
            shortcut.Save();
        }
コード例 #47
0
ファイル: MainWindow.xaml.cs プロジェクト: wertkh32/gg
        public void CreateShortcut()
        {
            if (File.Exists(ShortcutLink)) return;
               IWshRuntimeLibrary.WshShell wsh = new IWshRuntimeLibrary.WshShell();
               IWshRuntimeLibrary.IWshShortcut ggshortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(ShortcutLink);
               ggshortcut.TargetPath = Assembly.GetExecutingAssembly().Location;
               ggshortcut.IconLocation = (new FileInfo(Assembly.GetExecutingAssembly().Location)).DirectoryName + "\\gg.ico";
               ggshortcut.WorkingDirectory = (new FileInfo(Assembly.GetExecutingAssembly().Location)).DirectoryName;
               ggshortcut.Description = "GG";

               ggshortcut.Save();
        }
コード例 #48
0
ファイル: Main.cs プロジェクト: iheijoushin/Jackett
        private void CreateShortcut()
        {
#if __MonoCS__
            // No shortcuts on linux
#else
            var appPath = Assembly.GetExecutingAssembly().Location;
            var shell = new IWshRuntimeLibrary.WshShell();
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(ShortcutPath);
            shortcut.Description = Assembly.GetExecutingAssembly().GetName().Name;
            shortcut.TargetPath = appPath;
            shortcut.Save();
#endif
        }
コード例 #49
0
ファイル: function.cs プロジェクト: Windriderking/ME3Patch
 public static void link(string verion)
 {
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\" + "质量效应3" + verion + ".lnk");
     shortcut.TargetPath = System.Windows.Forms.Application.StartupPath + "\\Binaries\\Win32\\masseffect3.exe";
     shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
     shortcut.WindowStyle = 1;
     shortcut.Description = "质量效应3" + verion;
     shortcut.IconLocation = System.Windows.Forms.Application.StartupPath + "\\Binaries\\Win32\\masseffect3.exe";
     shortcut.Save();
 }
コード例 #50
0
 /// <summary>
 /// Creates a Shortcut of the current .exe at the Startup folder.
 /// </summary>
 public static void CreateStartupShortcut()
 {
     object shDesktop = (object)"Startup";
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
     string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\WallpaperClock.lnk";
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutAddress);
     shortcut.TargetPath = System.Windows.Forms.Application.ExecutablePath;
     shortcut.Save();
 }
コード例 #51
0
        private void btn1_Click(object sender, RoutedEventArgs e)
        {
            int index = 0;
            for (index = 0; index < steamGameName.Count; index++)
                if (steamGameName[index] == cb1.SelectedItem.ToString())
                    break;

            string curSteamGameId = steamGameId[index];

            string shortcutName = string.Join(string.Empty, cb1.SelectedItem.ToString().Split(Path.GetInvalidFileNameChars()));
            string curSteamGameDir = string.Format("{0}\\SteamApps\\common\\{1}", path, shortcutName);

            if (!string.IsNullOrEmpty(curSteamGameId))
            {
                OpenFileDialog getGameExe = new OpenFileDialog();
                getGameExe.DefaultExt = ".exe";
                getGameExe.Filter = "Executable File (*.exe) | *.exe";
                if (Directory.Exists(curSteamGameDir))
                    getGameExe.InitialDirectory = curSteamGameDir;
                else
                    getGameExe.InitialDirectory = Path.Combine(path, "SteamApps");

                if (SilDev.Reg.SubKeyExist("HKLM", string.Format("SOFTWARE\\Valve\\Steam\\Apps\\{0}", curSteamGameId)))
                {
                    string uplayGame = SilDev.Reg.ReadValue("HKLM", string.Format("SOFTWARE\\Valve\\Steam\\Apps\\{0}", curSteamGameId), "UplayLauncher");
                    if (!string.IsNullOrEmpty(uplayGame))
                    {
                        if (SilDev.Reg.SubKeyExist("HKLM", "SOFTWARE\\Ubisoft\\Launcher"))
                        {
                            string uplayPath = SilDev.Reg.ReadValue("HKLM", "SOFTWARE\\Ubisoft\\Launcher", "InstallDir");
                            if (!string.IsNullOrEmpty(uplayPath))
                            {
                                if (Directory.Exists(uplayPath))
                                    getGameExe.InitialDirectory = uplayPath;
                                if (File.Exists(Path.Combine(uplayPath, "Uplay.exe")))
                                    getGameExe.FileName = "Uplay.exe";
                            }
                        }
                    }
                }

                getGameExe.Title = ("Select the game executable file").ToUpper();
                bool? gameExeResult = getGameExe.ShowDialog();
                if (gameExeResult == true)
                {
                    string curSteamGameName = Path.GetFileNameWithoutExtension(getGameExe.FileName);
                    string shortcutIconPath = getGameExe.FileName;
                    if (curSteamGameName.ToLower() == "uplay")
                    {
                        OpenFileDialog getGameIcon = new OpenFileDialog();
                        getGameIcon.DefaultExt = ".exe|.ico";
                        getGameIcon.Filter = "Icon (*.exe, *.ico) | *.exe; *.ico"; ;
                        getGameIcon.InitialDirectory = Path.Combine(path, "steam\\games");
                        getGameIcon.Title = ("Select the game icon").ToUpper();
                        Nullable<bool> getGameIconResult = getGameIcon.ShowDialog();
                        if (getGameIconResult == true)
                            shortcutIconPath = getGameIcon.FileName;
                    }
                    try
                    {
                        IWshRuntimeLibrary.WshShell wshShell = new IWshRuntimeLibrary.WshShell();
                        IWshRuntimeLibrary.IWshShortcut desktopShortcut;
                        desktopShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), string.Format("{0}.lnk", shortcutName)));
                        desktopShortcut.Arguments = string.Format("\"{0}\" \"{1}\"", curSteamGameId, Path.GetFileNameWithoutExtension(getGameExe.FileName));
                        desktopShortcut.IconLocation = shortcutIconPath;
                        desktopShortcut.TargetPath = Environment.GetCommandLineArgs()[0];
                        desktopShortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
                        desktopShortcut.WindowStyle = 7;
                        desktopShortcut.Save();
                        MessageBox.Show(string.Format("Desktop shortcut for {0} created.", shortcutName), "Information", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Something was wrong, no shortcut created.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    }
                }
            }
        }
コード例 #52
0
 private static string ShortCutTargetFinder(string path)
 {
     /* finds target path of a .lnk shortcut file
     prerequisites:
     COM object: Windows Script Host Object Mode
     */
     if (System.IO.File.Exists(path))
     {
         IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); //Create a new WshShell Interface
         IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path); //Link the interface to our shortcut
         return link.TargetPath;
     }
     else
     {
         throw new FileNotFoundException();
     }
 }
コード例 #53
0
ファイル: Cache.cs プロジェクト: StarsCreator/Saturnus
        private void LoadStartMenu(string path)
        {
            //var dir = new DirectoryInfo(path);
            //foreach (var file in dir.GetFileSystemInfos())
            //    Console.WriteLine(file.FullName);
            //foreach (var pat in dir.GetDirectories()
            //    .Where(d => !d.Attributes.HasFlag(FileAttributes.NotContentIndexed)))
            //{
            //    foreach (var directoryInfo in pat.GetDirectories())
            //    {
            //        LoadStartMenu(directoryInfo.FullName);
            //    }
            //}

            var shell = new IWshRuntimeLibrary.WshShell();

            try
            {
                //var files = Directory.GetFiles(path);

                foreach (var file in Directory.GetFiles(path))
                {
                    var fileinfo = new FileInfo(file);

                    if (fileinfo.Extension.ToLower() != ".lnk") continue;
                    var link = shell.CreateShortcut(file) as IWshRuntimeLibrary.WshShortcut;
                    var sr = new Result(fileinfo.Name.Substring(0, fileinfo.Name.Length - 4),
                        link.TargetPath, file);
                    _cachedItems.Add(sr);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {

                foreach (var dir in Directory.GetDirectories(path))
                {
                    LoadStartMenu(dir);
                }
            }
        }
コード例 #54
0
ファイル: Form1.cs プロジェクト: atmozzis/Custom-Key-Logger
 private void btnCreateDesktopShortcut_Click(object sender, EventArgs e)
 {
     String ShortcutLnk = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Typing For Fun.lnk";
     if (!File.Exists(ShortcutLnk))
     {
         IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
         IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(ShortcutLnk);
         link.TargetPath = atmdir;
         link.Save();
     }
 }
コード例 #55
0
        private string FindLauncherPath()
        {
            string launcherPath = null;

            // attempt 1. Read the registry
            RegistryKey key = null;
            try
            {
                if (Environment.Is64BitOperatingSystem)
                    key = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Wow6432Node");
                if (key == null)
                    key = Registry.LocalMachine.OpenSubKey("SOFTWARE");
                key = key.OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion").OpenSubKey("Uninstall");
                key = key.OpenSubKey("{696F8871-C91D-4CB1-825D-36BE18065575}_is1");

                if (key != null)
                {
                    launcherPath = key.GetValue("InstallLocation") as string;
                }
            }
            catch
            {

            }

            if (launcherPath != null)
                return launcherPath;

            // attempt 2. try to read the shortcut in the program menu
            string menuPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs", "Frontier", "Elite Dangerous Launcher");
            string shortcut = Path.Combine(menuPath, "Elite Dangerous Launcher.lnk");

            if (File.Exists(shortcut))
            {
                var shell = new IWshRuntimeLibrary.WshShell();
                var lnk = shell.CreateShortcut(shortcut);

                string launcherExePath = lnk.TargetPath;
                launcherPath = new FileInfo(launcherExePath).DirectoryName;
            }

            // attempt 3. try the default path
            if (launcherPath == null)
            {
                if (File.Exists(Path.Combine(DefLauncherPath, "EDLaunch.exe")))
                    launcherPath = DefLauncherPath;
            }

            return launcherPath;
        }
コード例 #56
0
        public IMEFirmwareTool(string[] Argss)
        {
            InitializeComponent();
            Args = Argss;

            if (Settings.NeedsSettingsUpgrade)
            {
                Settings.Upgrade();
                Settings.NeedsSettingsUpgrade = false;
            }

            InstalledMEFirmwareVersionLabel.Text = "Installed ME Firmware Version: Calculating";
            FirmwareType.Text = "Firmware Type: Calculating";
            if (File.Exists(string.Format(@"{0}\{1}", Application.StartupPath, "error.log")))
                File.Delete(string.Format(@"{0}\{1}", Application.StartupPath, "error.log"));
            Settings.PropertyChanged += Settings_PropertyChanged;
            ForceResetCheckBox.Checked = Settings.ForceReset;
            AllowFlashingOfSameFirmwareVersionCheckBox.Checked = Settings.AllowSameVersion;

            BuildDate = ProgramInformation.GetBuildDateTime(ExecutablesFullPath);
            ProgramVersionLabel.Text = string.Format("Version: {0}", VersionUntouchedWithDots);
            BuildDateLabel.Text = string.Format("Build Date: {0}", BuildDate);

            CopyrightLabel.Text = string.Format("Copyright: {0}", ProgramInformation.AssemblyCopyright);

            try
            {
                if (!Debugging.IsDebugging)
                {
                    if (File.Exists(string.Format(@"{0}\{1}.dll", Application.StartupPath, "SevenZipSharp")))
                        File.Delete(string.Format(@"{0}\{1}.dll", Application.StartupPath, "SevenZipSharp"));

                    File.WriteAllBytes(string.Format(@"{0}\{1}.dll", Application.StartupPath, "SevenZipSharp"), Resources.SevenZipSharp);
                    File.SetAttributes(string.Format(@"{0}\{1}.dll", Application.StartupPath, "SevenZipSharp"),
                            File.GetAttributes(string.Format(@"{0}\{1}.dll", Application.StartupPath, "SevenZipSharp")) | FileAttributes.Hidden);
                }

                if (File.Exists(string.Format(@"{0}\{1}.dll", Application.StartupPath, "7z")))
                    File.Delete(string.Format(@"{0}\{1}.dll", Application.StartupPath, "7z"));

                File.WriteAllBytes(string.Format(@"{0}\{1}.dll", Application.StartupPath, "7z"), Resources._7z);
                File.SetAttributes(string.Format(@"{0}\{1}.dll", Application.StartupPath, "7z"),
                        File.GetAttributes(string.Format(@"{0}\{1}.dll", Application.StartupPath, "7z")) | FileAttributes.Hidden);
            }
            catch { }

            #region Program Shortcut
            if (!Directory.Exists(string.Format(@"{0}\{1}", Environment.GetFolderPath(Environment.SpecialFolder.Programs), Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location))))
                Directory.CreateDirectory(string.Format(@"{0}\{1}", Environment.GetFolderPath(Environment.SpecialFolder.Programs), Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)));
            IWshRuntimeLibrary.WshShell Shell = new IWshRuntimeLibrary.WshShell();
            IWshRuntimeLibrary.IWshShortcut Shortcut = (IWshRuntimeLibrary.IWshShortcut)Shell.CreateShortcut(Path.Combine(string.Format(@"{0}\{1}", Environment.GetFolderPath(Environment.SpecialFolder.Programs),
                Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)), string.Format("{0}.lnk", Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location))));
            Shortcut.Description = string.Format("{0} - {1}", Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location), ProgramInformation.AssemblyDescription);
            Shortcut.TargetPath = string.Format(@"{0}\{1}", Application.StartupPath, Path.GetFileName(Assembly.GetEntryAssembly().Location));
            Shortcut.Save();
            #endregion

            if (File.Exists(ProgramOldLocation))
                File.Delete(ProgramOldLocation);
        }
コード例 #57
0
 private FileInfo ResolveLink(FileInfo fileInfo)
 {
     IWshRuntimeLibrary.IWshShell shell = new IWshRuntimeLibrary.WshShell();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(fileInfo.FullName);
     
     return new FileInfo(shortcut.TargetPath);
 }
コード例 #58
0
ファイル: Form1.cs プロジェクト: mrddos/planisphere
        private bool CreateStartupMenu()
        {
            try
            {
                string p = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                string s = this.CreateStartupBatFile();
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();

                IWshRuntimeLibrary.WshShortcut shortcut = (IWshRuntimeLibrary.WshShortcut)shell.CreateShortcut(p + "\\startup.lnk");
                shortcut.TargetPath = s;
                shortcut.Arguments = "";
                shortcut.Description = "启动";
                shortcut.WorkingDirectory = this.installPath.Text;
                shortcut.IconLocation = string.Format("{0},0", s);
                shortcut.Save();

                this.AddLog("启动组快捷方式创建成功");
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
コード例 #59
0
ファイル: EditAppForm.cs プロジェクト: huipengly/WGestures
        private static string GetLnkTargetSimple(string lnkPath)
        {
            IWshRuntimeLibrary.IWshShell wsh = null;
            IWshRuntimeLibrary.IWshShortcut sc = null;

            try
            {
                wsh = new IWshRuntimeLibrary.WshShell();
                sc = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(lnkPath);
                return sc.TargetPath;
            }
            finally
            {
                if (wsh != null) Marshal.ReleaseComObject(wsh);
                if (sc != null) Marshal.ReleaseComObject(sc);
            }
        }
コード例 #60
0
ファイル: Class.xaml.cs プロジェクト: mikeyhalla/GClient
 public static string ResolveShortcut(string filePath)
 {
     Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture;
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
     try
     {
         IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
         return shortcut.TargetPath;
     }
     catch (COMException)
     {
         return null;
     }
 }