//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)
                     );
             }
         }
     }
 }
Exemplo n.º 2
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();
        }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
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;
		}
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var user = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

            Console.WriteLine(user);

            var desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            Console.WriteLine(desktop);

            var folders = AFolder.FromPairs(
                @"~\", "a-user",
                @"~\Downloads", "a-downloads",
                @"~\Documents", "a-documents",
                @"~\Projects", "a-projects-git",
                @"~\Google Drive", "a-drive",
                @"~\Google Drive\Projects", "a-projects-drive",
                @"~\Google Drive\Pictures", "a-pictures",
                @"~\Google Drive\Photos\Photography", "a-photography",
                @"~\Google Drive\Photos\Vision", "a-vision"
                );

            var icons = Path.Combine(user, @"Projects\a-windows-shortcuts\icons");


            foreach (var folder in folders)
            {
                string path = folder.Path;

                if (path.StartsWith(@"~\"))
                {
                    path = Path.Combine(user, path.Replace(@"~\", ""));
                }

                string desktopIni = Path.Combine(path, "desktop.ini");

                if (File.Exists(desktopIni))
                {
                    File.Delete(desktopIni);
                }

                string iconLocation = Path.Combine(icons, folder.Icon + ".ico") + ",0";

                try
                {
                    File.WriteAllLines(desktopIni, new String[] {
                        "[.ShellClassInfo]",
                        "IconResource=" + iconLocation,
                        "[ViewState]",
                        "Mode=",
                        "Vid=",
                        "FolderType=Generic"
                    });
                } catch
                {
                    Console.WriteLine("Cant create: desktop.ini");
                }

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

                var link = Path.Combine(desktop, folder.Icon + ".lnk");
                if (File.Exists(link))
                {
                    File.Delete(link);
                }

                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(link);
                shortcut.TargetPath   = @"C:\Windows\explorer.exe";
                shortcut.Arguments    = path;
                shortcut.IconLocation = iconLocation;
                shortcut.Save();

                Console.WriteLine("Ready: " + path);
            }



            Console.WriteLine("Done: All");
            Console.ReadKey();
        }
Exemplo n.º 10
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();
 }
Exemplo n.º 11
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();
              }
        }
Exemplo n.º 12
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 = ""
                });
            }
        }
Exemplo n.º 13
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();
 }
Exemplo n.º 14
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
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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();
 }
Exemplo n.º 19
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);
              }
        }
Exemplo n.º 20
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;
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
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;
		}