public bool OpenRemotePlay()
        {
            var path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);

            var exeLocation = path + @"\Sony\PS Remote Play\RemotePlay.exe";

            if (File.Exists(exeLocation))
            {
                Process.Start(exeLocation);
                return(true);
            }

            try
            {
                //TODO: hardcoded currently, so it doesn't work when OS is set to non-default system language.
                var shortcutPath = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PS Remote Play.lnk";
                IWshRuntimeLibrary.IWshShell    wsh = new IWshRuntimeLibrary.WshShellClass();
                IWshRuntimeLibrary.IWshShortcut sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(shortcutPath);
                shortcutPath = sc.TargetPath;

                if (string.IsNullOrEmpty(shortcutPath))
                {
                    return(false);
                }

                Process.Start(shortcutPath);
                return(true);
            }
            catch (Exception e)
            {
                Log.Logger.Error("Cannot open RemotePlay: " + e.Message);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Creates a new Windows shortcut.
        /// </summary>
        private 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.WshShellClass();
            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
        }
Example #3
0
        public static ShortcutInfo GetShortcutInfo(string path)
        {
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();

            if (path.ToLower().EndsWith("lnk"))
            {
                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);
                string realPath = shortcut.TargetPath;
                string iconloc  = shortcut.IconLocation;
                string args     = shortcut.Arguments;

                return(new ShortcutInfo()
                {
                    ExePath = realPath,
                    Arguments = args,
                    Icon = iconloc,
                    LnkPath = path
                });
            }
            else
            {
                return(new ShortcutInfo()
                {
                    ExePath = path,
                    LnkPath = path,
                    Arguments = "",
                    Icon = ""
                });
            }
        }
        /// <summary>
        /// Create Windows shortcut in directory (such as Desktop) to open TE or Flex project.
        /// </summary>
        private bool CreateProjectShortcut(string applicationArguments,
                                           string shortcutDescription, string directory)
        {
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();

            string filename = Cache.ProjectId.UiName;

            filename = Path.ChangeExtension(filename, "lnk");
            string linkPath = Path.Combine(directory, filename);

            IWshRuntimeLibrary.IWshShortcut link =
                (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkPath);
            if (link.FullName != linkPath)
            {
                var msg = string.Format(FrameworkStrings.ksCannotCreateShortcut,
                                        m_app.ProductExecutableFile + " " + applicationArguments);
                MessageBox.Show(Form.ActiveForm, msg,
                                FrameworkStrings.ksCannotCreateShortcutCaption, MessageBoxButtons.OK,
                                MessageBoxIcon.Asterisk);
                return(true);
            }
            link.TargetPath   = m_app.ProductExecutableFile;
            link.Arguments    = applicationArguments;
            link.Description  = shortcutDescription;
            link.IconLocation = link.TargetPath + ",0";
            link.Save();

            return(true);
        }
Example #5
0
    private void OnClick(BaseButton obj)
    {
        GameFilePathData gameFilePathData = MainData.Instance.Game_filePathData.Find(p => p.directoryInfo.Name == (obj as GameContentButton).GetName());
        FileInfo         fileInfo         = gameFilePathData.fileInfos.Find(p => p.Extension.ToUpper() == ".LNK");

        IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShellClass();
        IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(fileInfo.FullName);

        Application.OpenURL(shortcut.FullName);
        Debug.Log(shortcut.FullName);
        int lenth = 0;

        while (!shortcut.FullName.Substring(shortcut.FullName.Length - 15 - lenth, 1).Contains(@"\"))
        {
            lenth++;
        }
        // 除去自己"\"
        lenth--;
        string ProcessName = shortcut.FullName.Substring(shortcut.FullName.Length - 15 - lenth, lenth);

        Debug.Log("ProcessName:" + ProcessName);
        MainData.Instance.isMainWindow = false;
        KinectManager.Instance.ClearKinectUsers();
        TimeTool.Instance.AddDelayed(TimeDownType.NoUnityTimeLineImpact, 2.0f, () => {
            MainPanel.Instance.audioSource.Pause();
            SoftwareSettingsTool.Instance.productName = ProcessName;
        });

        lastUIPanel.Hide();
    }
 /// <summary>
 /// 创建快捷方式
 /// </summary>
 public static void CreateShortcut(string targetPath, string shortcutPath)
 {
     IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShellClass();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(shortcutPath);
     shortcut.TargetPath = targetPath;
     shortcut.Save();
 }
Example #7
0
        protected bool OpenRemotePlayInternal()
        {
            string exeLocation = ApplicationSettings.GetInstance().RemotePlayPath;

            if (File.Exists(exeLocation))
            {
                Process.Start(exeLocation);
                Log.Information("RemotePlayStarter.OpenRemotePlayInternal start requested-54");
                return(true);
            }

            try
            {
                //TODO: hardcoded currently, so it doesn't work when OS is set to non-default system language.
                string shortcutPath = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PS Remote Play.lnk";
                IWshRuntimeLibrary.IWshShell    wsh = new IWshRuntimeLibrary.WshShellClass();
                IWshRuntimeLibrary.IWshShortcut sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(shortcutPath);
                shortcutPath = sc.TargetPath;

                if (string.IsNullOrEmpty(shortcutPath))
                {
                    return(false);
                }

                Process.Start(shortcutPath);
                Log.Information("RemotePlayStarter.OpenRemotePlay start requested-73");
                return(true);
            }
            catch (Exception e)
            {
                ExceptionLogger.LogException("RemotePlayStarter.OpenRemotePlayInternal Cannot open RemotePlay", e);
            }

            return(false);
        }
 //Creates or Remove startup shortcut from Startup folder
 private void CreateStartupShortcut(bool create)
 {
     if (create)
     {
         IWshRuntimeLibrary.WshShellClass shell = null;
         IWshRuntimeLibrary.IWshShortcut  link  = null;
         try
         {
             shell                 = new IWshRuntimeLibrary.WshShellClass();
             link                  = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(StartupShortcutLocation);
             link.TargetPath       = Application.ExecutablePath;
             link.WorkingDirectory = AppConfig.CurrentDirectory;
             link.Save();
         }
         catch (UnauthorizedAccessException)
         {
             MessageBox.Show(
                 string.Format("You do not have sufficient access rights to create the shortcut in the Startup directory (\"{0}\")", Environment.GetFolderPath(Environment.SpecialFolder.Startup))
                 );
         }
         catch (Exception)
         {
             MessageBox.Show(
                 string.Format(
                     "Unable to create the shortcut in startup folder. Please try again later or add it manually in \"{0}\".\nIf problem persist, you may have insufficient rights to perform this action.",
                     Environment.GetFolderPath(Environment.SpecialFolder.Startup))
                 );
         }
         finally
         {
             shell = null;
             link  = null;
         }
     }
     else
     {
         if (System.IO.File.Exists(StartupShortcutLocation))
         {
             try
             {
                 System.IO.File.Delete(StartupShortcutLocation);
             }
             catch (UnauthorizedAccessException)
             {
                 MessageBox.Show(
                     string.Format("You do not have sufficient access rights to remove the shortcut from the Startup directory (\"{0}\")", Environment.GetFolderPath(Environment.SpecialFolder.Startup))
                     );
             }
             catch (Exception)
             {
                 MessageBox.Show(
                     string.Format(
                         "Unable to remove the shortcut from folder. Please try again later or remove it manually from \"{0}\"\nIf problem persist, you may have insufficient rights to perform this action.",
                         StartupShortcutLocation)
                     );
             }
         }
     }
 }
Example #9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle the Create Shortcut on Desktop menu/toolbar item.
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public bool OnCreateShortcut(object args)
        {
            CheckDisposed();

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

            string desktopFolder =
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string database = Cache.DatabaseName;
            string project  = Cache.LangProject.Name.UserDefaultWritingSystem;
            bool   remote   = !MiscUtils.IsServerLocal(Cache.ServerName);
            string filename = "";

            if (remote)
            {
                string[] server = Cache.ServerName.Split('\\');
                if (server.Length > 0)
                {
                    filename =
                        string.Format(FwApp.GetResourceString("kstidCreateShortcutFilenameRemoteDb"), database, server[0]) +
                        ".lnk";
                }
            }
            else
            {
                filename = database + ".lnk";
            }
            string linkPath = Path.Combine(desktopFolder, filename);

            IWshRuntimeLibrary.IWshShortcut link =
                (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkPath);
            link.TargetPath = Application.ExecutablePath;
            link.Arguments  = "-db \"" + database + "\"";
            if (remote)
            {
                link.Arguments += " -c \"" + Cache.ServerName + "\"";
            }
            if (project == database)
            {
                link.Description = string.Format(
                    FwApp.GetResourceString("kstidCreateShortcutLinkDescription"),
                    project, database, Application.ProductName);
            }
            else
            {
                link.Description = string.Format(
                    FwApp.GetResourceString("kstidCreateShortcutLinkDescriptionAlt"),
                    project, database, Application.ProductName);
            }
            link.IconLocation = Application.ExecutablePath + ",0";
            link.Save();

            return(true);
        }
Example #10
0
        /// <summary>
        /// Возвращает информацию о ярлыке <paramref name="shortcutFilename"/> в формате <i>"путь к обьекту" аргументы</i>.
        /// </summary>
        /// <param name="shortcutFilename">Путь ярлыка.</param>
        /// <returns>Объект, на который указывает ярлык и аргументы.</returns>
        public static string GetShortcutTargetFileAndArgs(string shortcutFilename)
        {
            IWshRuntimeLibrary.IWshShell    wsh = new IWshRuntimeLibrary.WshShellClass();
            IWshRuntimeLibrary.IWshShortcut sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(shortcutFilename);
            if (string.IsNullOrEmpty(sc?.TargetPath))
            {
                return(string.Empty);
            }

            return($"\"{sc.TargetPath}\" {sc.Arguments}");
        }
        public static void Install()
        {
            string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            var    shortcut          = Path.Combine(startUpFolderPath, "HistoryFilter.lnk");

            IWshRuntimeLibrary.IWshShell    wsh = new IWshRuntimeLibrary.WshShellClass();
            IWshRuntimeLibrary.IWshShortcut sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(shortcut);
            sc.TargetPath       = Application.ExecutablePath;
            sc.WorkingDirectory = Application.StartupPath;
            sc.Description      = "Start HistoryFilter on system start";
            sc.Save();
        }
Example #12
0
 /// <summary>
 /// 读取Lnk文件的路径
 /// </summary>
 /// <param name="filePath"></param>
 /// <returns></returns>
 public string GetLnkFile(string filePath)
 {
     IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShellClass();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(filePath);
     //shortcut.TargetPath = "指向地址.exe";
     //shortcut.Arguments = "参数";
     //shortcut.Description = "我是快捷方式名字哦!";
     //shortcut.Hotkey = "CTRL+SHIFT+N";
     //shortcut.IconLocation = "notepad.exe, 0";
     //shortcut.Save();
     return(shortcut.TargetPath);
 }
Example #13
0
        private static void SendKeysToApp(string partialAppTitle, string keys)
        {
            var shell   = new IWshRuntimeLibrary.WshShellClass();
            var app     = (object)partialAppTitle;
            var success = shell.AppActivate(ref app);

            if (success)
            {
                shell.SendKeys(keys);
            }

            Marshal.ReleaseComObject(shell);
        }
Example #14
0
 /// <summary>
 /// 创建快捷方式
 /// </summary>
 /// <param name="lnkPath">快捷方式完整路径</param>
 /// <param name="sourcePath">源文件路径</param>
 public static void CreatShortCut(this string lnkPath,string sourcePath)
 {
     if (!File.Exists(lnkPath))
     {
         IWshRuntimeLibrary.WshShellClass desk = new IWshRuntimeLibrary.WshShellClass();
         var temp = desk.CreateShortcut(lnkPath) as IWshRuntimeLibrary.IWshShortcut;
         temp.TargetPath = sourcePath;
         temp.WorkingDirectory = Directory.GetParent(sourcePath).FullName;
         temp.WindowStyle = 1;
         temp.IconLocation = sourcePath;
         temp.Save();
     }
 }
Example #15
0
 /// <summary>
 /// 创建快捷方式
 /// </summary>
 /// <param name="lnkPath">快捷方式完整路径</param>
 /// <param name="sourcePath">源文件路径</param>
 public static void CreatShortCut(this string lnkPath, string sourcePath)
 {
     if (!File.Exists(lnkPath))
     {
         IWshRuntimeLibrary.WshShellClass desk = new IWshRuntimeLibrary.WshShellClass();
         var temp = desk.CreateShortcut(lnkPath) as IWshRuntimeLibrary.IWshShortcut;
         temp.TargetPath       = sourcePath;
         temp.WorkingDirectory = Directory.GetParent(sourcePath).FullName;
         temp.WindowStyle      = 1;
         temp.IconLocation     = sourcePath;
         temp.Save();
     }
 }
Example #16
0
        void CreateShortCut(string path, string targetPath, string Arguments, string workingDirectory)
        {
            var wsc = new IWshRuntimeLibrary.WshShellClass();

            var ws = (IWshRuntimeLibrary.WshShortcut)(wsc.CreateShortcut(path));

            ws.TargetPath       = targetPath;       // @"C:\Windows\Notepad.exe";
            ws.IconLocation     = ws.TargetPath + ",0";
            ws.Arguments        = Arguments;        // @"""C:\Temp\Test.txt""";
            ws.WorkingDirectory = workingDirectory; // @"C:\Temp";

            // ショートカットの保存
            ws.Save();
        }
Example #17
0
        private static void CreateShortcut(string shortcutPath, string shortcutTarget, string shortcutIcon, string shortcutDescription)
        {
            var wsh = new IWshRuntimeLibrary.WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(shortcutPath) as IWshRuntimeLibrary.IWshShortcut;
            //shortcut.Arguments = "c:\\app\\settings1.xml";
            shortcut.TargetPath = shortcutTarget;
            // not sure about what this is for
            shortcut.WindowStyle      = 1;
            shortcut.Description      = shortcutDescription;
            shortcut.WorkingDirectory = Path.GetDirectoryName(shortcutTarget);
            shortcut.IconLocation     = shortcutIcon;
            shortcut.Save();
        }
Example #18
0
        public static void create_shortcut()
        { // code from codeproject
            IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
            IWshRuntimeLibrary.IWshShortcut  shortcut;
            string startUpFolderPath =
                Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            // Create the shortcut
            shortcut                  = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(startUpFolderPath + "\\" + Application.ProductName + ".lnk");
            shortcut.TargetPath       = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Description      = "File Hasher";
            shortcut.Save();
        }
Example #19
0
        private void install(Object par)
        {
            List <string> param = (List <string>)par;

            try
            {
                Directory.CreateDirectory(dirpath);
                DirectoryInfo di = new DirectoryInfo(Directory.GetCurrentDirectory());
                if (IsServer)
                {
                    if (IsCreateDB)
                    {
                        String      CreateDBSQL = "CREATE DATABASE IF NOT EXISTS " + param[0];
                        OdbcCommand CreateDB    = new OdbcCommand(CreateDBSQL, conn);
                        CreateDB.ExecuteNonQuery();
                    }
                    Restore(Directory.GetCurrentDirectory() + "\\template.sql", "localhost", param[0], param[1], param[2]);
                }
                foreach (FileInfo fi in di.GetFiles())
                {
                    File.Copy(fi.FullName, dirpath + "\\" + fi.Name, true);
                }
                IWshRuntimeLibrary.WshShellClass WshShell = new IWshRuntimeLibrary.WshShellClass();
                IWshRuntimeLibrary.IWshShortcut  Shortcut1;
                Shortcut1                  = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Stock Control and Billing System.lnk");
                Shortcut1.TargetPath       = dirpath + "\\StockControl.exe";
                Shortcut1.Description      = "Stock Control and Billing System";
                Shortcut1.WorkingDirectory = dirpath;
                Shortcut1.Save();
                IWshRuntimeLibrary.IWshShortcut Shortcut2;
                //   Directory.CreateDirectory(Environment.SpecialFolder.StartMenu + "\\Stock Control and Billing System");
                Shortcut2                  = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Stock Control and Billing System.lnk");
                Shortcut2.TargetPath       = dirpath + "\\StockControl.exe";
                Shortcut2.Description      = "Stock Control and Billing System";
                Shortcut2.WorkingDirectory = dirpath;
                Shortcut2.Save();
                changePB();
                finishwork = true;
            }
            catch (Exception e)
            {
                finishworkwitherror = true;
                changePB();
                MessageBox.Show("Setup cannot continue because " + e.Message + "\n\n", "Error - Setup cannot continue", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                finishwork = true;
            }
        }
Example #20
0
        /// <summary>
        /// 获取所有桌面图标
        /// </summary>
        /// <returns></returns>
        public static List <ShortcutInfo> GetAllDesktopShortcuts()
        {
            var path  = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var files = System.IO.Directory.GetFiles(path);

            var ret      = new List <ShortcutInfo>();
            var fileList = (from j in files where !j.EndsWith("ini") select j).ToList();

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

            foreach (var item in fileList)
            {
                ret.Add(GetShortcutInfo(item));
            }

            return(ret);
        }
Example #21
0
        public static string GetOutlookEntryIDFromShortcut(string shortcutPath)
        {
            string entryID = String.Empty;

            IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
            IWshRuntimeLibrary.IWshShortcut  shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath);
            if (shortcut != null)
            {
                string arguments = shortcut.Arguments;

                // Sample arguments = outlook:000000007E9E0115FB90D348B60A3CCC64FCEAC364002000

                entryID = arguments.Substring(arguments.IndexOf("outlook:") + 8);
            }

            return(entryID);
        }
Example #22
0
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="description"></param>
        /// <param name="root"></param>
        /// <param name="ico"></param>
        public void CreateCutFile(string fileName, string description, string root, string ico)
        {
            string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹

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


            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\ERP系统.lnk");
            shortcut.TargetPath       = fileName;
            shortcut.Arguments        = "";     // 参数
            shortcut.Description      = description;
            shortcut.WorkingDirectory = root;   //程序所在文件夹,在快捷方式图标点击右键可以看到此属性
            //shortcut.IconLocation = @"D:\software\cmpc\zy.exe,0";//图标
            shortcut.IconLocation = ico + ",0"; //图标
            //shortcut.Hotkey = "CTRL+SHIFT+Z";//热键
            shortcut.WindowStyle = 1;
            shortcut.Save();
        }
        private void CreateShortcut()
        {
            var targetdir = Context.Parameters["TARGETDIR"];
            var programMenuFolder = Context.Parameters["ProgramMenuFolder"];

            var shell = new IWshRuntimeLibrary.WshShellClass();

            var shortcutPath = Path.Combine( programMenuFolder, "MongoDB\\MongoDB Command Prompt.lnk" );
            var shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut( shortcutPath );

            shortcut.TargetPath = "%COMSPEC%";

            shortcut.Arguments = string.Format( "/K \"{0}\"", Path.Combine( targetdir, "MongoDB Command Prompt.bat" ) );

            shortcut.WorkingDirectory = Path.Combine( targetdir, "MongoDB\\bin" );

            shortcut.Description = "Open MongoDB Command Prompt";
            shortcut.Save();
        }
Example #24
0
        private static void CreateShortcut(string executablePath, string path)
        {
            // 声明操作对象
            IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();
            string filename = Path.GetFileName(executablePath);
            string file     = path + "\\" + filename + ".lnk";

            // 创建一个快捷方式
            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(file);
            // 关联的程序
            shortcut.TargetPath = executablePath;
            // 参数
            //shortcut.Arguments = "";
            // 快捷方式描述,鼠标放到快捷方式上会显示出来哦
            shortcut.Description = filename + "应用程序";
            // 全局热键
            //shortcut.Hotkey = "CTRL+SHIFT+N";
            // 设置快捷方式的图标,这里是取程序图标,如果希望指定一个ico文件,那么请写路径。
            //shortcut.IconLocation = "notepad.exe, 0";
            // 保存,创建就成功了。
            shortcut.Save();
        }
Example #25
0
        private void CreateShortcutWin(string name, string destFile, string arguments = "", string description = "")
        {
            var lnkFile = StartMenuDir + dsc + name + ".lnk";

            if (File.Exists(lnkFile))
            {
                Utils.UIDeleteFile(lnkFile);
            }
            var lnkDir = Path.GetDirectoryName(lnkFile);

            if (!Directory.Exists(lnkDir))
            {
                Directory.CreateDirectory(lnkDir);
            }
            var wsh = new IWshRuntimeLibrary.WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(lnkFile) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.TargetPath       = destFile;
            shortcut.Arguments        = arguments;
            shortcut.Description      = description;
            shortcut.WorkingDirectory = Path.GetDirectoryName(destFile);;
            shortcut.Save();
        }
Example #26
0
        private static string GetLnkTargetSimple(string lnkPath)
        {
            IWshRuntimeLibrary.IWshShell    wsh = null;
            IWshRuntimeLibrary.IWshShortcut sc  = null;

            try
            {
                wsh = new IWshRuntimeLibrary.WshShellClass();
                sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(lnkPath);
                return(sc.TargetPath);
            }
            finally
            {
                if (wsh != null)
                {
                    Marshal.ReleaseComObject(wsh);
                }
                if (sc != null)
                {
                    Marshal.ReleaseComObject(sc);
                }
            }
        }
 public static void UpdateCreateShortCutOnDesktop()
 {
     try
     {
         string lnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\BaronReplays.lnk";
         if (Properties.Settings.Default.CreateShortCutOnDesktop)
         {
             IWshRuntimeLibrary.WshShellClass shell    = new IWshRuntimeLibrary.WshShellClass();
             IWshRuntimeLibrary.IWshShortcut  shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(lnkPath);
             shortcut.TargetPath = Process.GetCurrentProcess().MainModule.FileName;
             shortcut.Save();
         }
         else
         {
             if (System.IO.File.Exists(lnkPath))
             {
                 System.IO.File.Delete(lnkPath);
             }
         }
     }
     catch (Exception e)
     {
     }
 }
        public string GetInkTargetPath(string path, string fileName)
        {
            string        result        = string.Empty;
            DirectoryInfo directoryInfo = new DirectoryInfo(path);

            FileSystemInfo[] fileSystemInfos = directoryInfo.GetFileSystemInfos();
            foreach (var item in fileSystemInfos)
            {
                try
                {
                    string fullName = item.FullName;
                    if (Directory.Exists(fullName))
                    {
                        result = GetInkTargetPath(fullName, fileName);
                        if (result != string.Empty)
                        {
                            return(result);
                        }
                    }
                    else
                    {
                        if (item.Name == fileName)
                        {
                            IWshRuntimeLibrary.WshShell     shell    = new IWshRuntimeLibrary.WshShellClass();
                            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(fullName);
                            return(shortcut.TargetPath);
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
            }
            return(result);
        }
Example #29
0
        private static Process ExecuteCommand(string pWorkDir, string pExecutable, string pArguments, string pProcessName,
                                              bool pShowInstanceWindow, string pIconFile, bool pProcessNameViaShortcut, AemInstance pAemInstance)
        {
            mLog.Info("Execute: WorkDir=" + pWorkDir + ", executable=" + pExecutable + ", arguments=" + pArguments);

            Process process;

            // execute via auto-generated shortcut
            if (pShowInstanceWindow && pProcessNameViaShortcut)
            {
                string shortcutFilename = Path.GetTempPath() + pProcessName + ".lnk";

                IWshRuntimeLibrary.WshShell     wshShell = new IWshRuntimeLibrary.WshShellClass();
                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutFilename);

                if (!string.IsNullOrEmpty(pWorkDir))
                {
                    shortcut.WorkingDirectory = pWorkDir;
                }
                try {
                    shortcut.TargetPath = pExecutable;
                }
                catch (ArgumentException) {
                    MessageBox.Show("Executable not found: " + pExecutable, "Execute Command", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return(null);
                }
                shortcut.Arguments   = pArguments;
                shortcut.Description = pProcessName;
                if (!string.IsNullOrEmpty(pIconFile))
                {
                    shortcut.IconLocation = Path.GetDirectoryName(Application.ExecutablePath) + "\\icons\\" + pIconFile;
                }
                shortcut.Save();

                process = new Process();
                process.StartInfo.FileName = shortcutFilename;
            }

            // start directly
            else
            {
                process = new Process();
                if (!string.IsNullOrEmpty(pWorkDir))
                {
                    process.StartInfo.WorkingDirectory = pWorkDir;
                }
                process.StartInfo.FileName  = pExecutable;
                process.StartInfo.Arguments = pArguments;
            }

            if (!pShowInstanceWindow)
            {
                process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            }

            if (pProcessNameViaShortcut)
            {
                // use shellexecute if start via shortcut is used - this forbids using output stream redirection etc.
                process.StartInfo.UseShellExecute = true;
            }
            else
            {
                // directy start process if no shortcut is used.
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.CreateNoWindow  = !pShowInstanceWindow;
                if (pAemInstance != null && !pShowInstanceWindow)
                {
                    // use output handling if AEM instance is available
                    process.OutputDataReceived += new DataReceivedEventHandler(pAemInstance.ConsoleOutputWindow.Process_OutputDataReceived);
                    process.StartInfo.RedirectStandardOutput = true;
                    process.ErrorDataReceived += new DataReceivedEventHandler(pAemInstance.ConsoleOutputWindow.Process_ErrorDataReceived);
                    process.StartInfo.RedirectStandardError = true;
                }
            }

            try {
                process.Start();

                if (!pProcessNameViaShortcut)
                {
                    if (pAemInstance != null && !pShowInstanceWindow)
                    {
                        process.BeginOutputReadLine();
                        process.BeginErrorReadLine();
                    }
                }

                return(process);
            }
            catch (Exception ex) {
                throw new Exception(ex.Message + "\n"
                                    + "WorkDir: " + pWorkDir + "\n"
                                    + "Executable: " + pExecutable + "\n"
                                    + "Arguments: " + pArguments, ex);
            }
        }
Example #30
0
        private static string GetLnkTargetSimple(string lnkPath)
        {
            IWshRuntimeLibrary.IWshShell wsh = null;
            IWshRuntimeLibrary.IWshShortcut sc = null;

            try
            {
                wsh = new IWshRuntimeLibrary.WshShellClass();
                sc = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(lnkPath);
                return sc.TargetPath;
            }
            finally
            {
                if (wsh != null) Marshal.ReleaseComObject(wsh);
                if (sc != null) Marshal.ReleaseComObject(sc);
            }
        }
Example #31
0
 public static string LnkToFile(string fileLink)
 {
     IWshRuntimeLibrary.IWshShell    wsh = new IWshRuntimeLibrary.WshShellClass();
     IWshRuntimeLibrary.IWshShortcut sc  = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(fileLink);
     return(sc.TargetPath);
 }
        private static List<Element> ConvertXML(string dirPath, XmlDocument xmlDoc)
        {
            List<Element> elementList = new List<Element>();

            XmlNode xmlRootNode = xmlDoc.GetElementsByTagName(XML_ROOT)[0];
            int position = 0;
            String currentDir = dirPath;

            foreach (XmlNode xmlElement in xmlRootNode.ChildNodes)
            {
                try
                {
                    //add new element into the XML file
                    Element element = new Element();
                    element.ID = new Guid(xmlElement.Attributes[XML_ELEMENT_GUID].Value);
                    element.AssociationURI = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                    bool isDiscoverable = Boolean.Parse(xmlElement.Attributes[XML_ELEMENT_DISCOVERABLE].Value);
                    if (isDiscoverable)
                    {
                        element.LevelOfSynchronization = 1;
                    }
                    else
                    {
                        element.LevelOfSynchronization = 0;
                    }
                    element.NoteText = xmlElement.Attributes[XML_ELEMENT_NOTETEXT].Value;
                    element.AssociationType = (ElementAssociationType)Enum.Parse(typeof(ElementAssociationType), xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE].Value);
                    element.IsVisible = System.Windows.Visibility.Visible;
                    element.Type = (ElementType)Enum.Parse(typeof(ElementType), xmlElement.Attributes[XML_ELEMENT_TYPE].Value);
                    element.IsExpanded = Boolean.Parse(xmlElement.Attributes[XML_ELEMENT_ISEXPANDED].Value);
                    switch (xmlElement.Attributes[XML_ELEMENT_STATUS].Value)
                    {
                        case "Flag":
                            element.Status = ElementStatus.Normal;
                            element.FlagStatus = FlagStatus.Flag;
                            element.ShowFlag = System.Windows.Visibility.Visible;
                            element.FlagImageSource = String.Format("pack://application:,,,/{0};component/{1}", "Planz", "Images/flag.gif");
                            break;
                        case "Check":
                            element.Status = ElementStatus.Normal;
                            element.FlagStatus = FlagStatus.Check;
                            element.ShowFlag = System.Windows.Visibility.Visible;
                            element.FlagImageSource = String.Format("pack://application:,,,/{0};component/{1}", "Planz", "Images/check.gif");
                            break;
                        default:
                            element.Status = (ElementStatus)Enum.Parse(typeof(ElementStatus), xmlElement.Attributes[XML_ELEMENT_STATUS].Value);
                            element.FlagImageSource = String.Format("pack://application:,,,/{0};component/{1}", "Planz", "Images/normal.gif");
                            element.FlagStatus = FlagStatus.Normal;
                            break;
                    };
                    element.PowerDStatus = PowerDStatus.None;
                    element.FontColor = xmlElement.Attributes[XML_ELEMENT_HIGHLIGHT].Value;
                    element.Position = position++;
                    element.Tag = xmlElement.Attributes[XML_ELEMENT_TAG].Value;

                    //to be corrected
                    if (element.AssociationURI != String.Empty)
                    {
                        if (element.IsLocalHeading && System.IO.Directory.Exists(currentDir + element.AssociationURI))
                        {
                            // If the associated folder exists
                            element.TailImageSource = FileTypeHandler.GetIcon((ElementAssociationType)element.AssociationType, currentDir + element.AssociationURI);
                        }
                        else if (System.IO.File.Exists(currentDir + element.AssociationURI))
                        {
                            // If the associated file exists
                            element.TailImageSource = FileTypeHandler.GetIcon((ElementAssociationType)element.AssociationType, currentDir + element.AssociationURI);
                        }
                        else
                        {
                            // If the associated file is missing
                            element.TailImageSource = FileTypeHandler.GetMissingFileIcon();
                            element.FontColor = ElementColor.Gray.ToString();
                            element.Status = ElementStatus.MissingAssociation;
                        }
                    }

                    switch (element.Type)
                    {
                        case ElementType.Heading:
                            if (element.IsRemoteHeading)
                            {
                                IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
                                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(currentDir + element.AssociationURI);
                                if (shortcut != null)
                                {
                                    element.Path = shortcut.TargetPath + System.IO.Path.DirectorySeparatorChar;
                                }
                            }
                            else
                            {
                                element.Path = currentDir + HeadingNameConverter.ConvertFromHeadingNameToFolderName(element) + System.IO.Path.DirectorySeparatorChar;
                                element.TailImageSource = FileTypeHandler.GetIcon(ElementAssociationType.Folder, element.Path);
                            }

                            if (System.IO.Directory.Exists(element.Path))
                            {
                            }
                            else
                            {
                                // If the associated folder is missing
                                element.Type = ElementType.Note;
                                element.IsExpanded = false;
                                element.FontColor = ElementColor.Gray.ToString();
                                element.Status = ElementStatus.MissingAssociation;
                                element.AssociationType = ElementAssociationType.None;
                                element.AssociationURI = String.Empty;
                                element.TailImageSource = String.Empty;
                            }
                            break;
                        case ElementType.Note:
                            break;
                    };
                    elementList.Add(element);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
            elementList.Sort(new SortByPosition());
            return elementList;
        }
        private static List<Element> ConvertXML(string dirPath, XmlDocument xmlDoc)
        {
            List<Element> elementList = new List<Element>();

            XmlNode xmlRootNode = xmlDoc.GetElementsByTagName(XML_ROOT)[0];

            foreach (XmlNode xmlElement in xmlRootNode.ChildNodes)
            {
                try
                {
                    Element element = new Element();

                    element.ID = new Guid(xmlElement.Attributes[XML_ELEMENT_GUID].Value);
                    element.NoteText = xmlElement.Attributes[XML_ELEMENT_NOTETEXT].Value;
                    element.Position = Int32.Parse(xmlElement.Attributes[XML_ELEMENT_POSITION].Value);
                    element.IsExpanded = !Boolean.Parse(xmlElement.Attributes[XML_ELEMENT_ISCOLLAPSED].Value);
                    element.Status = ElementStatus.Normal;

                    switch (xmlElement.Name)
                    {
                        case XML_HEADING:
                            element.Type = ElementType.Heading;
                            element.AssociationURI = HeadingNameConverter.ConvertFromHeadingNameToFolderName(element);
                            element.AssociationType = ElementAssociationType.Folder;
                            element.FontColor = ElementColor.DarkBlue.ToString();
                            if (element.IsExpanded)
                            {
                                element.LevelOfSynchronization = 1;
                            }
                            else
                            {
                                element.LevelOfSynchronization = 0;
                            }
                            break;
                        case XML_NOTE:
                        case XML_LINK:
                        case XML_MAIL:
                        case XML_WORD:
                        case XML_EXCEL:
                        case XML_PPT:
                        default:
                            element.Type = ElementType.Note;
                            element.LevelOfSynchronization = 0;
                            break;
                    };

                    if (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI] != null)
                    {
                        element.AssociationURI = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                    }

                    if (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE] != null)
                    {
                        switch (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE].Value)
                        {
                            case XML_ELEMENT_ASSOCIATIONTYPE_FOLDERSHORTCUT:
                                element.AssociationType = ElementAssociationType.FolderShortcut;
                                break;
                            case XML_ELEMENT_ASSOCIATIONTYPE_FILESHORTCUT:
                                element.AssociationType = ElementAssociationType.FileShortcut;
                                break;
                            case XML_ELEMENT_ASSOCIATIONTYPE_WEB:
                                element.AssociationType = ElementAssociationType.Web;
                                break;
                            case XML_ELEMENT_ASSOCIATIONTYPE_FILE:
                            case XML_ELEMENT_ASSOCIATIONTYPE_NONE:
                            default:
                                element.AssociationType = ElementAssociationType.File;
                                break;
                        };
                    }
                    else
                    {
                        if (xmlElement.Name == XML_WORD ||
                            xmlElement.Name == XML_EXCEL ||
                            xmlElement.Name == XML_PPT)
                        {
                            element.AssociationType = ElementAssociationType.File;
                        }
                    }

                    // In-place expansion will be converted to Note with folder shortcut
                    if (xmlElement.Attributes[XML_ELEMENT_FOLDERLINK] != null)
                    {
                        element.Type = ElementType.Heading;
                        element.AssociationURI = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                        element.IsExpanded = false;
                        element.AssociationType = ElementAssociationType.FolderShortcut;
                        element.LevelOfSynchronization = 1;
                    }

                    // Email
                    if (xmlElement.Name == XML_MAIL)
                    {
                        string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromEmailSubject(element.NoteText, dirPath);
                        string shortcutPath = dirPath + shortcutName;
                        IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
                        IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath);

                        string targetPath = OutlookSupportFunction.GenerateShortcutTargetPath();
                        shortcut.TargetPath = targetPath;
                        shortcut.Arguments = "/select outlook:" + xmlElement.Attributes[XML_MAIL_ENTRYID].Value;
                        shortcut.Description = targetPath;

                        shortcut.Save();

                        element.AssociationType = ElementAssociationType.Email;
                        element.AssociationURI = shortcutName;
                    }

                    elementList.Add(element);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }

            elementList.Sort(new SortByPosition());

            return elementList;
        }
Example #34
0
        private static Process ExecuteCommand(string pWorkDir, string pExecutable, string pArguments, string pProcessName,
            bool pShowInstanceWindow, string pIconFile, bool pProcessNameViaShortcut, AemInstance pAemInstance)
        {
            mLog.Info("Execute: WorkDir=" + pWorkDir + ", executable=" + pExecutable + ", arguments=" + pArguments);

              Process process;

              // execute via auto-generated shortcut
              if (pShowInstanceWindow && pProcessNameViaShortcut) {
            string shortcutFilename = Path.GetTempPath() + pProcessName + ".lnk";

            IWshRuntimeLibrary.WshShell wshShell = new IWshRuntimeLibrary.WshShellClass();
            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutFilename);

            if (!string.IsNullOrEmpty(pWorkDir)) {
              shortcut.WorkingDirectory = pWorkDir;
            }
            try {
              shortcut.TargetPath = pExecutable;
            }
            catch (ArgumentException) {
              MessageBox.Show("Executable not found: " + pExecutable, "Execute Command", MessageBoxButtons.OK, MessageBoxIcon.Warning);
              return null;
            }
            shortcut.Arguments = pArguments;
            shortcut.Description = pProcessName;
            if (!string.IsNullOrEmpty(pIconFile)) {
              shortcut.IconLocation = Path.GetDirectoryName(Application.ExecutablePath) + "\\icons\\" + pIconFile;
            }
            shortcut.Save();

            process = new Process();
            process.StartInfo.FileName = shortcutFilename;
              }

              // start directly
              else {
            process = new Process();
            if (!string.IsNullOrEmpty(pWorkDir)) {
              process.StartInfo.WorkingDirectory = pWorkDir;
            }
            process.StartInfo.FileName = pExecutable;
            process.StartInfo.Arguments = pArguments;
              }

              if (!pShowInstanceWindow) {
            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
              }

              if (pProcessNameViaShortcut) {
            // use shellexecute if start via shortcut is used - this forbids using output stream redirection etc.
            process.StartInfo.UseShellExecute = true;
              }
              else {
            // directy start process if no shortcut is used.
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.CreateNoWindow = !pShowInstanceWindow;
            if (pAemInstance != null && !pShowInstanceWindow) {
              // use output handling if AEM instance is available
              process.OutputDataReceived += new DataReceivedEventHandler(pAemInstance.ConsoleOutputWindow.Process_OutputDataReceived);
              process.StartInfo.RedirectStandardOutput = true;
              process.ErrorDataReceived += new DataReceivedEventHandler(pAemInstance.ConsoleOutputWindow.Process_ErrorDataReceived);
              process.StartInfo.RedirectStandardError = true;
            }
              }

              try {
            process.Start();

            if (!pProcessNameViaShortcut) {
              if (pAemInstance != null && !pShowInstanceWindow) {
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();
              }
            }

            return process;
              }
              catch (Exception ex) {
            throw new Exception(ex.Message + "\n"
              + "WorkDir: " + pWorkDir + "\n"
              + "Executable: " + pExecutable + "\n"
              + "Arguments: " + pArguments, ex);
              }
        }
        private static List <Element> ConvertXML(string dirPath, XmlDocument xmlDoc)
        {
            List <Element> elementList = new List <Element>();

            XmlNode xmlRootNode = xmlDoc.GetElementsByTagName(XML_ROOT)[0];

            foreach (XmlNode xmlElement in xmlRootNode.ChildNodes)
            {
                try
                {
                    Element element = new Element();

                    element.ID         = new Guid(xmlElement.Attributes[XML_ELEMENT_GUID].Value);
                    element.NoteText   = xmlElement.Attributes[XML_ELEMENT_NOTETEXT].Value;
                    element.Position   = Int32.Parse(xmlElement.Attributes[XML_ELEMENT_POSITION].Value);
                    element.IsExpanded = !Boolean.Parse(xmlElement.Attributes[XML_ELEMENT_ISCOLLAPSED].Value);
                    element.Status     = ElementStatus.Normal;

                    switch (xmlElement.Name)
                    {
                    case XML_HEADING:
                        element.Type            = ElementType.Heading;
                        element.AssociationURI  = HeadingNameConverter.ConvertFromHeadingNameToFolderName(element);
                        element.AssociationType = ElementAssociationType.Folder;
                        element.FontColor       = ElementColor.DarkBlue.ToString();
                        if (element.IsExpanded)
                        {
                            element.LevelOfSynchronization = 1;
                        }
                        else
                        {
                            element.LevelOfSynchronization = 0;
                        }
                        break;

                    case XML_NOTE:
                    case XML_LINK:
                    case XML_MAIL:
                    case XML_WORD:
                    case XML_EXCEL:
                    case XML_PPT:
                    default:
                        element.Type = ElementType.Note;
                        element.LevelOfSynchronization = 0;
                        break;
                    }
                    ;

                    if (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI] != null)
                    {
                        element.AssociationURI = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                    }

                    if (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE] != null)
                    {
                        switch (xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONTYPE].Value)
                        {
                        case XML_ELEMENT_ASSOCIATIONTYPE_FOLDERSHORTCUT:
                            element.AssociationType = ElementAssociationType.FolderShortcut;
                            break;

                        case XML_ELEMENT_ASSOCIATIONTYPE_FILESHORTCUT:
                            element.AssociationType = ElementAssociationType.FileShortcut;
                            break;

                        case XML_ELEMENT_ASSOCIATIONTYPE_WEB:
                            element.AssociationType = ElementAssociationType.Web;
                            break;

                        case XML_ELEMENT_ASSOCIATIONTYPE_FILE:
                        case XML_ELEMENT_ASSOCIATIONTYPE_NONE:
                        default:
                            element.AssociationType = ElementAssociationType.File;
                            break;
                        }
                        ;
                    }
                    else
                    {
                        if (xmlElement.Name == XML_WORD ||
                            xmlElement.Name == XML_EXCEL ||
                            xmlElement.Name == XML_PPT)
                        {
                            element.AssociationType = ElementAssociationType.File;
                        }
                    }

                    // In-place expansion will be converted to Note with folder shortcut
                    if (xmlElement.Attributes[XML_ELEMENT_FOLDERLINK] != null)
                    {
                        element.Type                   = ElementType.Heading;
                        element.AssociationURI         = xmlElement.Attributes[XML_ELEMENT_ASSOCIATIONURI].Value;
                        element.IsExpanded             = false;
                        element.AssociationType        = ElementAssociationType.FolderShortcut;
                        element.LevelOfSynchronization = 1;
                    }

                    // Email
                    if (xmlElement.Name == XML_MAIL)
                    {
                        string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromEmailSubject(element.NoteText, dirPath);
                        string shortcutPath = dirPath + shortcutName;
                        IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
                        IWshRuntimeLibrary.IWshShortcut  shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath);

                        string targetPath = OutlookSupportFunction.GenerateShortcutTargetPath();
                        shortcut.TargetPath  = targetPath;
                        shortcut.Arguments   = "/select outlook:" + xmlElement.Attributes[XML_MAIL_ENTRYID].Value;
                        shortcut.Description = targetPath;

                        shortcut.Save();

                        element.AssociationType = ElementAssociationType.Email;
                        element.AssociationURI  = shortcutName;
                    }

                    elementList.Add(element);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }

            elementList.Sort(new SortByPosition());

            return(elementList);
        }
Example #36
0
        static void Main(string[] args)
        {
            if (args.Length < 2) {
            System.Windows.Forms.MessageBox.Show(
            "Need to provide directories for generated shortcuts and icons");
            System.Environment.Exit(1);
              }

              string shortcutDirectory = args[0];
              string iconDirectory = args[1];

              if (!Directory.Exists(shortcutDirectory)) {
            System.Windows.Forms.MessageBox.Show(String.Format(
              "Directory {0} doesn't exist", shortcutDirectory));
            System.Environment.Exit(1);
              }

              if (!Directory.Exists(iconDirectory)) {
            System.Windows.Forms.MessageBox.Show(String.Format(
              "Directory {0} doesn't exist", iconDirectory));
            System.Environment.Exit(1);
              }

              if (args.Length < 3) {
            System.Windows.Forms.MessageBox.Show(
            "Need the path for the rsh.exe utility");
            System.Environment.Exit(1);
              }

              string rshCommand = args[2];

              if (!File.Exists(rshCommand)) {
            System.Windows.Forms.MessageBox.Show(String.Format(
              "File {0} doesn't exist", iconDirectory));
            System.Environment.Exit(1);
              }

              if (args.Length < 4)
              {
            System.Windows.Forms.MessageBox.Show(
            "Need listen address");
            System.Environment.Exit(1);
              }

              string listenIp = args[3];
              int listenPort = 55556;

              if (args.Length < 5)
              {
            System.Windows.Forms.MessageBox.Show(
            "Need virtualbox guest user");
            System.Environment.Exit(1);
              }

              string user = args[4];

              server = new TcpListener(IPAddress.Parse(listenIp), listenPort);
              server.Start();

              while (true)
              {
            TcpClient client = server.AcceptTcpClient();
            string ip = client.Client.RemoteEndPoint.ToString().Split(':')[0];

            // Keep eveything in sync by deleting all shortcuts and icons when
            // a new connection is accepted
            foreach (string item in Directory.GetFiles(shortcutDirectory, "*.lnk"))
              File.Delete(item);

            foreach (string item in Directory.GetFiles(iconDirectory, "*.ico"))
              File.Delete(item);

            IWshRuntimeLibrary.WshShellClass wsh =
              new IWshRuntimeLibrary.WshShellClass();

            // Get the connection stream
            NetworkStream stream = client.GetStream();

            // BinaryReader makes easier to parse binary data
            BinaryReader reader = new BinaryReader(stream);

            while (reader.ReadByte() != 0)
            {
              // next entry

              // read icon
              int iconLength = reader.ReadInt32();
              byte[] iconData = null;
              if (iconLength != 0) {
            iconData = reader.ReadBytes(iconLength);
              }

              // read name
              int nameLength = reader.ReadInt32();
              byte[] nameData = reader.ReadBytes(nameLength);
              string name = Encoding.UTF8.GetString(nameData, 0, nameLength);
              // remove invalid substrings in paths
              name = name.Replace(@"\", @" ").Replace(@"/", @" ").Replace(":", "");
              name += " (Ubuntu)";

              // read command
              int commandLength = reader.ReadInt32();
              byte[] commandData = reader.ReadBytes(commandLength);
              string command = Encoding.UTF8.GetString(commandData, 0,
              commandLength);

              // Create icon if provided
              string iconPath = null;
              if (iconData != null) {
            iconPath = Path.Combine(iconDirectory, name + ".ico");
            iconPath = iconPath.Replace(@"\", @"\\");
            File.WriteAllBytes(iconPath, iconData);
              }

              string scpath = Path.Combine(shortcutDirectory, name + ".lnk");
              scpath = scpath.Replace(@"\", @"\\");
              // Create shortcut and wrap command into a tcp-command call
              IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(scpath)
            as IWshRuntimeLibrary.IWshShortcut;
              shortcut.TargetPath = rshCommand;
              shortcut.Arguments = String.Format("{0} -l {1} $SHELL -l -c '{2}'", ip, user, command);
              // not sure about what this is for
              shortcut.WindowStyle = 1;
              shortcut.Description = name;
              shortcut.WorkingDirectory = Path.GetDirectoryName(rshCommand);
              if (iconData != null)
            shortcut.IconLocation = iconPath;
              shortcut.Save();
            }

            // Close connection
            stream.Close();
              }
        }
Example #37
0
 private void CreateShortcutWin(string name, string destFile, string arguments = "", string description = "")
 {
     var lnkFile = StartMenuDir + dsc + name + ".lnk";
     if (File.Exists(lnkFile))
         Utils.UIDeleteFile(lnkFile);
     var lnkDir = Path.GetDirectoryName(lnkFile);
     if (!Directory.Exists(lnkDir)) Directory.CreateDirectory(lnkDir);
     var wsh = new IWshRuntimeLibrary.WshShellClass();
     IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(lnkFile) as IWshRuntimeLibrary.IWshShortcut;
     shortcut.TargetPath = destFile;
     shortcut.Arguments = arguments;
     shortcut.Description = description;
     shortcut.WorkingDirectory = Path.GetDirectoryName(destFile); ;
     shortcut.Save();
 }
Example #38
0
 private static void CreateDesktopLnk()
 {
     System.Console.WriteLine("开始创建桌面快捷方式...");
     int i = 0;
     while(!File.Exists(appPath + @"\UI.exe")&&i<20)
     {
         Thread.Sleep(500);
         System.Console.WriteLine(i.ToString() + "...");
         i++;
     }
     string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(DesktopPath + "\\体检系统.lnk");
     shortcut.TargetPath = appPath + @"\UI.exe";
     shortcut.Arguments = "";// 参数
     shortcut.Description = "体检系统";
     shortcut.WorkingDirectory = appPath;//程序所在文件夹,在快捷方式图标点击右键可以看到此属性
     shortcut.IconLocation = appPath + @"\UI.exe,0";//图标
     shortcut.Hotkey = "CTRL+SHIFT+T";//热键
     shortcut.WindowStyle = 1;
     shortcut.Save();
 }
Example #39
0
		/// <summary>
		/// Create Windows shortcut in directory (such as Desktop) to open TE or Flex project.
		/// </summary>
		private bool CreateProjectShortcut(string applicationArguments,
			string shortcutDescription, string directory)
		{
			IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();

			string filename = Cache.ProjectId.UiName;
			filename = Path.ChangeExtension(filename, "lnk");
			string linkPath = Path.Combine(directory, filename);

			IWshRuntimeLibrary.IWshShortcut link =
				(IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkPath);
			if (link.FullName != linkPath)
			{
				var msg = string.Format(FrameworkStrings.ksCannotCreateShortcut,
					m_app.ProductExecutableFile + " " + applicationArguments);
				MessageBox.Show(Form.ActiveForm, msg,
					FrameworkStrings.ksCannotCreateShortcutCaption, MessageBoxButtons.OK,
					MessageBoxIcon.Asterisk);
				return true;
			}
			link.TargetPath = m_app.ProductExecutableFile;
			link.Arguments = applicationArguments;
			link.Description = shortcutDescription;
			link.IconLocation = link.TargetPath + ",0";
			link.Save();

			return true;
		}
Example #40
0
 private static void CreateShortcut(string shortcutPath, string shortcutTarget, string shortcutIcon, string shortcutDescription)
 {
     var wsh = new IWshRuntimeLibrary.WshShellClass();
     IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(shortcutPath) as IWshRuntimeLibrary.IWshShortcut;
     //shortcut.Arguments = "c:\\app\\settings1.xml";
     shortcut.TargetPath = shortcutTarget;
     // not sure about what this is for
     shortcut.WindowStyle = 1;
     shortcut.Description = shortcutDescription;
     shortcut.WorkingDirectory = Path.GetDirectoryName(shortcutTarget);
     shortcut.IconLocation = shortcutIcon;
     shortcut.Save();
 }
Example #41
0
        /// <summary>
        /// Creates a new Windows shortcut.
        /// </summary>
        private 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.WshShellClass();
            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
        }
Example #42
0
        public static string GetOutlookEntryIDFromShortcut(string shortcutPath)
        {
            string entryID = String.Empty;

            IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();
            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutPath);
            if (shortcut != null)
            {
                string arguments = shortcut.Arguments;

                // Sample arguments = outlook:000000007E9E0115FB90D348B60A3CCC64FCEAC364002000

                entryID = arguments.Substring(arguments.IndexOf("outlook:") + 8);
            }

            return entryID;
        }
Example #43
0
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Need to provide directories for generated shortcuts and icons");
                System.Environment.Exit(1);
            }

            string shortcutDirectory = args[0];
            string iconDirectory     = args[1];

            if (!Directory.Exists(shortcutDirectory))
            {
                System.Windows.Forms.MessageBox.Show(String.Format(
                                                         "Directory {0} doesn't exist", shortcutDirectory));
                System.Environment.Exit(1);
            }

            if (!Directory.Exists(iconDirectory))
            {
                System.Windows.Forms.MessageBox.Show(String.Format(
                                                         "Directory {0} doesn't exist", iconDirectory));
                System.Environment.Exit(1);
            }

            if (args.Length < 3)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Need the path for the rsh.exe utility");
                System.Environment.Exit(1);
            }

            string rshCommand = args[2];

            if (!File.Exists(rshCommand))
            {
                System.Windows.Forms.MessageBox.Show(String.Format(
                                                         "File {0} doesn't exist", iconDirectory));
                System.Environment.Exit(1);
            }

            if (args.Length < 4)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Need listen address");
                System.Environment.Exit(1);
            }

            string listenIp   = args[3];
            int    listenPort = 55556;

            if (args.Length < 5)
            {
                System.Windows.Forms.MessageBox.Show(
                    "Need virtualbox guest user");
                System.Environment.Exit(1);
            }

            string user = args[4];

            server = new TcpListener(IPAddress.Parse(listenIp), listenPort);
            server.Start();

            while (true)
            {
                TcpClient client = server.AcceptTcpClient();
                string    ip     = client.Client.RemoteEndPoint.ToString().Split(':')[0];

                // Keep eveything in sync by deleting all shortcuts and icons when
                // a new connection is accepted
                foreach (string item in Directory.GetFiles(shortcutDirectory, "*.lnk"))
                {
                    File.Delete(item);
                }

                foreach (string item in Directory.GetFiles(iconDirectory, "*.ico"))
                {
                    File.Delete(item);
                }

                IWshRuntimeLibrary.WshShellClass wsh =
                    new IWshRuntimeLibrary.WshShellClass();

                // Get the connection stream
                NetworkStream stream = client.GetStream();

                // BinaryReader makes easier to parse binary data
                BinaryReader reader = new BinaryReader(stream);

                while (reader.ReadByte() != 0)
                {
                    // next entry

                    // read icon
                    int    iconLength = reader.ReadInt32();
                    byte[] iconData   = null;
                    if (iconLength != 0)
                    {
                        iconData = reader.ReadBytes(iconLength);
                    }

                    // read name
                    int    nameLength = reader.ReadInt32();
                    byte[] nameData   = reader.ReadBytes(nameLength);
                    string name       = Encoding.UTF8.GetString(nameData, 0, nameLength);
                    // remove invalid substrings in paths
                    name  = name.Replace(@"\", @" ").Replace(@"/", @" ").Replace(":", "");
                    name += " (Ubuntu)";

                    // read command
                    int    commandLength = reader.ReadInt32();
                    byte[] commandData   = reader.ReadBytes(commandLength);
                    string command       = Encoding.UTF8.GetString(commandData, 0,
                                                                   commandLength);

                    // Create icon if provided
                    string iconPath = null;
                    if (iconData != null)
                    {
                        iconPath = Path.Combine(iconDirectory, name + ".ico");
                        iconPath = iconPath.Replace(@"\", @"\\");
                        File.WriteAllBytes(iconPath, iconData);
                    }

                    string scpath = Path.Combine(shortcutDirectory, name + ".lnk");
                    scpath = scpath.Replace(@"\", @"\\");
                    // Create shortcut and wrap command into a tcp-command call
                    IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(scpath)
                                                               as IWshRuntimeLibrary.IWshShortcut;
                    shortcut.TargetPath = rshCommand;
                    shortcut.Arguments  = String.Format("{0} -l {1} $SHELL -l -c '{2}'", ip, user, command);
                    // not sure about what this is for
                    shortcut.WindowStyle      = 1;
                    shortcut.Description      = name;
                    shortcut.WorkingDirectory = Path.GetDirectoryName(rshCommand);
                    if (iconData != null)
                    {
                        shortcut.IconLocation = iconPath;
                    }
                    shortcut.Save();
                }

                // Close connection
                stream.Close();
            }
        }
Example #44
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handle the Create Shortcut on Desktop menu/toolbar item.
		/// </summary>
		/// <param name="args"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public bool OnCreateShortcut(object args)
		{
			CheckDisposed();

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

			string desktopFolder =
				Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
			string database = Cache.DatabaseName;
			string project = Cache.LangProject.Name.UserDefaultWritingSystem;
			bool remote = !MiscUtils.IsServerLocal(Cache.ServerName);
			string filename = "";
			if (remote)
			{
				string[] server = Cache.ServerName.Split('\\');
				if (server.Length > 0)
				{
					filename =
						string.Format(FwApp.GetResourceString("kstidCreateShortcutFilenameRemoteDb"), database, server[0]) +
						".lnk";
				}
			}
			else
			{
				filename = database + ".lnk";
			}
			string linkPath = Path.Combine(desktopFolder, filename);

			IWshRuntimeLibrary.IWshShortcut link =
				(IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(linkPath);
			link.TargetPath = Application.ExecutablePath;
			link.Arguments = "-db \"" + database + "\"";
			if (remote)
			{
				link.Arguments += " -c \"" + Cache.ServerName + "\"";
			}
			if (project == database)
			{
				link.Description = string.Format(
					FwApp.GetResourceString("kstidCreateShortcutLinkDescription"),
					project, database, Application.ProductName);
			}
			else
			{
				link.Description = string.Format(
					FwApp.GetResourceString("kstidCreateShortcutLinkDescriptionAlt"),
					project, database, Application.ProductName);
			}
			link.IconLocation = Application.ExecutablePath + ",0";
			link.Save();

			return true;
		}