Ejemplo n.º 1
0
        public List <LinkType> LoadLinksFromStartup()
        {
            DirectoryInfo di = new DirectoryInfo(GetStartupPath());

            FileInfo[]      files       = di.GetFiles("*DelayStartup.lnk");
            List <LinkType> listOfLinks = new List <LinkType>();

            foreach (FileInfo fi in files)
            {
                //parse link into string
                string pathOnly     = Path.GetDirectoryName(fi.FullName);
                string filenameOnly = Path.GetFileName(fi.FullName);

                Shell32.Shell      shell      = new Shell32.ShellClass();
                Shell32.Folder     folder     = shell.NameSpace(pathOnly);
                Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);

                if (folderItem != null)
                {
                    Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                    LinkType a = new LinkType(link, fi);
                    listOfLinks.Add(a);
                }
            }
            return(listOfLinks);
        }
Ejemplo n.º 2
0
            private static string GetShortcutTargetFile(string shortcutFilename)
            {
                string pathOnly     = Path.GetDirectoryName(shortcutFilename);
                string filenameOnly = Path.GetFileName(shortcutFilename);

                Type ShellAppType = Type.GetTypeFromProgID("Shell.Application");

                if (ShellAppType != null)
                {
                    Shell32.Shell shell = Activator.CreateInstance(ShellAppType) as Shell32.Shell;
                    if (shell != null)
                    {
                        Shell32.Folder folder = shell.NameSpace(pathOnly);
                        if (folder != null)
                        {
                            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
                            if (folderItem != null)
                            {
                                Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                                return(link.Path);
                            }
                        }
                    }
                }
                return(String.Empty); // Not found
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Get duration(ms) of audio or vedio by Shell32.dll
        /// </summary>
        /// <param name="filePath">audio/vedio's path</param>
        /// <returns>Duration in original format, duration in milliseconds</returns>
        /// <remarks>return value from Shell32.dll is in format of: "00:10:16"</remarks>
        public override Tuple <string, long> GetDuration(string filePath)
        {
            try
            {
                string dir = Path.GetDirectoryName(filePath);

                // From Add Reference --> COM
                Shell              shell      = new Shell32.Shell();
                Shell32.Folder     folder     = shell.NameSpace(dir);
                Shell32.FolderItem folderitem = folder.ParseName(Path.GetFileName(filePath));

                string duration = null;

                // Deal with different versions of OS
                if (Environment.OSVersion.Version.Major >= 6)
                {
                    duration = folder.GetDetailsOf(folderitem, 27);
                }
                else
                {
                    duration = folder.GetDetailsOf(folderitem, 21);
                }

                duration = string.IsNullOrEmpty(duration) ? "00:00:00" : duration;
                return(Tuple.Create(duration, GetTimeInMillisecond(duration)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        //http://csharphelper.com/blog/2018/06/get-information-about-windows-shortcuts-in-c/
        internal static string GetShortcutInfo(string full_name,
                                               out string name, out string path, out string descr,
                                               out string working_dir, out string args)
        {
            name        = "";
            path        = "";
            descr       = "";
            working_dir = "";
            args        = "";
            try
            {
                // Make a Shell object.
                Shell32.Shell shell = new Shell32.Shell();

                // Get the shortcut's folder and name.
                string shortcut_path =
                    full_name.Substring(0, full_name.LastIndexOf("\\"));
                string shortcut_name =
                    full_name.Substring(full_name.LastIndexOf("\\") + 1);
                if (!shortcut_name.EndsWith(".lnk"))
                {
                    shortcut_name += ".lnk";
                }

                // Get the shortcut's folder.
                Shell32.Folder shortcut_folder =
                    shell.NameSpace(shortcut_path);

                // Get the shortcut's file.
                Shell32.FolderItem folder_item =
                    shortcut_folder.Items().Item(shortcut_name);

                if (folder_item == null)
                {
                    return("Cannot find shortcut file '" + full_name + "'");
                }
                if (!folder_item.IsLink)
                {
                    return("File '" + full_name + "' isn't a shortcut.");
                }

                // Display the shortcut's information.
                Shell32.ShellLinkObject lnk =
                    (Shell32.ShellLinkObject)folder_item.GetLink;
                name        = folder_item.Name;
                descr       = lnk.Description;
                path        = lnk.Path;
                working_dir = lnk.WorkingDirectory;
                args        = lnk.Arguments;
                return("");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Converts a Shell32.FolderItem to a FolderItem
 /// </summary>
 /// <param name="folderItem">The shell folder item</param>
 /// <returns>The folder item</returns>
 private static FolderItem FromShellFolderItem(Shell32.FolderItem folderItem)
 {
     return(new FolderItem()
     {
         IsFolder = folderItem.IsFolder,
         Path = folderItem.Path,
         Name = folderItem.Name,
         Size = folderItem.Size,
         ModifiedDate = folderItem.ModifyDate
     });
 }
Ejemplo n.º 6
0
        public static MP3File ReadID3Tags(string FileFullPath)
        {
            MP3File mp3File = new MP3File();

            //parse file name
            string fileName = FileFullPath.Substring(FileFullPath.LastIndexOf("\\") + 1);
            //parse file path
            string filePath = FileFullPath.Substring(0, FileFullPath.LastIndexOf("\\"));

            //create shell instance
            Shell32.Shell shell = new Shell32.ShellClass();
            //set the namespace to file path
            Shell32.Folder folder = shell.NameSpace(filePath);
            //get ahandle to the file
            Shell32.FolderItem folderItem = folder.ParseName(fileName);
            //did we get a handle ?
            if (folderItem != null)
            {
                mp3File.FileName = fileName.Trim();
                //query information from shell regarding file
                mp3File.ArtistName = folder.GetDetailsOf(folderItem, 16).Trim();
                mp3File.AlbumName  = folder.GetDetailsOf(folderItem, 17).Trim();
                mp3File.SongTitle  = folder.GetDetailsOf(folderItem, 10).Trim();
                mp3File.Genre      = folder.GetDetailsOf(folderItem, 20).Trim();
                mp3File.Time       = folder.GetDetailsOf(folderItem, 21).Trim();
                mp3File.Duration   = folder.GetDetailsOf(folderItem, 27).Trim();
                string[] tags = new string[25];
                for (int i = 0; i < 25; i++)
                {
                    try
                    {
                        tags[i] = folder.GetDetailsOf(folderItem, i);
                    }
                    catch
                    {
                    }
                }
                mp3File.FileFullPath = FileFullPath.Trim();
                try
                {
                    mp3File.TrackNumber = Int32.Parse(folder.GetDetailsOf(folderItem, 19));
                }
                catch
                {
                }
            }
            //clean ip
            folderItem = null;
            folder     = null;
            shell      = null;
            //return mp3File instance
            return(mp3File);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取媒体文件播放时长///
        /// </summary>
        /// <param name="path">媒体文件路径</param>
        /// <returns></returns>
        public TimeSpan GetMediaTimeLen(string path)
        {
            Shell32.Shell shell = new Shell32.ShellClass( );
            //文件路径
            Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
            //文件名称
            Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
            string             _duration  = Regex.Match(folder.GetDetailsOf(folderitem, -1), "\\d:\\d{2}:\\d{2}").Value;

            string[] sp = _duration.Split(new char[] { ':' });
            TimeSpan ts = new TimeSpan(int.Parse(sp[0]), int.Parse(sp[1]), int.Parse(sp[2]));

            return(ts);
        }
Ejemplo n.º 8
0
        private static string GetShortcutTargetFile(string shortcutFilename)
        {
            string pathOnly     = Path.GetDirectoryName(shortcutFilename);
            string filenameOnly = Path.GetFileName(shortcutFilename);

            Shell32.Shell      shell      = new Shell32.ShellClass();
            Shell32.Folder     folder     = shell.NameSpace(pathOnly);
            Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
            if (folderItem != null)
            {
                Shell32.ShellLinkObject link =
                    (Shell32.ShellLinkObject)folderItem.GetLink;
                return(link.Path);
            }
            return(String.Empty);
        }
Ejemplo n.º 9
0
        public static string GetShortcutTargetFile(string shortcutFilename)
        {
            string directory = Path.GetDirectoryName(shortcutFilename);
            string filename  = Path.GetFileName(shortcutFilename);

            S32.Shell      shell  = new S32.ShellClass();
            S32.Folder     folder = shell.NameSpace(directory);
            S32.FolderItem item   = folder.ParseName(filename);

            if (item == null)
            {
                return(String.Empty);
            }

            S32.ShellLinkObject link = (S32.ShellLinkObject)item.GetLink;
            return(link.Path);
        }
Ejemplo n.º 10
0
        ///// <summary>
        ///// 文件地址
        ///// </summary>
        //public string Url
        //{
        //    get { return url; }
        //}
        public Mp3Message(string FilePath)
        {
            //url = GetRootURI()+FilePath.Remove(0,FilePath.IndexOf("\\upload\\")).Replace("\\","/");
            Shell32.Shell shell = new Shell32.ShellClass();
            //set the namespace to file path
            Shell32.Folder folder = shell.NameSpace(FilePath.Substring(0, FilePath.LastIndexOf("\\")));
            //get ahandle to the file
            Shell32.FolderItem folderItem = folder.ParseName(FilePath.Substring(FilePath.LastIndexOf("\\") + 1));
            //did we get a handle ?

            title   = folder.GetDetailsOf(folderItem, 9);
            artist  = folder.GetDetailsOf(folderItem, 16);
            album   = folder.GetDetailsOf(folderItem, 10);
            pubyear = folder.GetDetailsOf(folderItem, 18);
            genre   = folder.GetDetailsOf(folderItem, 12);
            size    = folder.GetDetailsOf(folderItem, 1);
            type    = folder.GetDetailsOf(folderItem, 2);
            bps     = folder.GetDetailsOf(folderItem, 22);
            track   = folder.GetDetailsOf(folderItem, 34);
        }
Ejemplo n.º 11
0
        public WmaMessage(string path)
        {
            //create shell instance
            Shell32.Shell shell = new Shell32.ShellClass();
            //set the namespace to file path
            Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
            //get ahandle to the file
            Shell32.FolderItem folderItem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
            //did we get a handle ?

            title   = folder.GetDetailsOf(folderItem, 9);
            artist  = folder.GetDetailsOf(folderItem, 16);
            album   = folder.GetDetailsOf(folderItem, 10);
            pubyear = folder.GetDetailsOf(folderItem, 18);
            genre   = folder.GetDetailsOf(folderItem, 12);
            size    = folder.GetDetailsOf(folderItem, 1);
            type    = folder.GetDetailsOf(folderItem, 2);
            bps     = folder.GetDetailsOf(folderItem, 22);
            track   = folder.GetDetailsOf(folderItem, 34);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// ファイルの再生時間取得(Win7用)
        /// </summary>
        /// <param name="path">ファイルパス</param>
        /// <returns></returns>
        private TimeSpan GetFileTime(string path)
        {
            TimeSpan ts = new TimeSpan(0, 0, 0, 0);

            Shell32.Folder folder = null;

            string someDirectory = System.IO.Path.GetDirectoryName(path);

            string someFile = System.IO.Path.GetFileName(path);

            try
            {
                Type   wshell      = Type.GetTypeFromProgID("Shell.Application");
                object wshInstance = Activator.CreateInstance(wshell);
                folder = (Shell32.Folder)wshell.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, wshInstance, new object[] { someDirectory });
            }
            catch {
                return(ts);
            }

            Shell32.FolderItem folderitem = folder.ParseName(someFile);

            try
            {
                // 再生時間の表示。ただし7上。XPでは 27 ではなく 21 となる。
                string   times       = folder.GetDetailsOf(folderitem, 27);
                string[] stArrayData = times.Split(':');
                int      o           = int.Parse(stArrayData[0]);
                int      m           = int.Parse(stArrayData[1]);
                int      s           = int.Parse(stArrayData[2]);

                ts = new TimeSpan(o, m, s);
                return(ts);
            }
            catch {
                return(ts);
            }
        }
Ejemplo n.º 13
0
            public FileAccesser(string fullPath, string name, Shell32.Folder folder)
            {
                this.FullPath = fullPath;

                this.file = null;
                if (folder != null)
                {
                    try
                    {
                        this.file   = folder.ParseName(name);
                        this.folder = folder;
                    }
                    catch
                    {
                        this.file   = null;
                        this.folder = null;
                    }
                }
                else
                {
                    this.file   = null;
                    this.folder = null;
                }
            }
Ejemplo n.º 14
0
        //http://csharphelper.com/blog/2018/06/get-information-about-windows-shortcuts-in-c/
        // Get information about this link.
        // Return an error message if there's a problem.
        internal static string GetShortcutInfo(string full_name,
                                               out ShortcutItem vSI)
        {
            //name = "";
            //path = "";
            //descr = "";
            //working_dir = "";
            //args = "";
            //var sc = Keys.Control && Keys.LShiftKey && Keys.A;
            //var txt = new KeysConverter().ConvertToString((Keys)sc);
            //Console.WriteLine(txt);



            vSI = new ShortcutItem();

            try
            {
                // Make a Shell object.
                Shell32.Shell shell = new Shell32.Shell();

                // Get the shortcut's folder and name.
                string shortcut_path =
                    full_name.Substring(0, full_name.LastIndexOf("\\"));
                string shortcut_name =
                    full_name.Substring(full_name.LastIndexOf("\\") + 1);
                if (!shortcut_name.EndsWith(".lnk"))
                {
                    shortcut_name += ".lnk";
                }

                // Get the shortcut's folder.
                Shell32.Folder shortcut_folder =
                    shell.NameSpace(shortcut_path);

                // Get the shortcut's file.
                Shell32.FolderItem folder_item =
                    shortcut_folder.Items().Item(shortcut_name);

                if (folder_item == null)
                {
                    return("Cannot find shortcut file '" + full_name + "'");
                }
                if (!folder_item.IsLink)
                {
                    return("File '" + full_name + "' isn't a shortcut.");
                }

                // Display the shortcut's information.
                Shell32.ShellLinkObject lnk = (Shell32.ShellLinkObject)folder_item.GetLink;

                vSI.Arguments   = lnk.Arguments;
                vSI.Description = lnk.Description;
                //vSI.Hotkey = lnk.Hotkey.ToString();
                lnk.GetIconLocation(out string bps);
                vSI.IconPath     = bps;
                vSI.Name         = folder_item.Name;
                vSI.ShortcutPath = lnk.Path;
                FolderItem fi = lnk.Target;
                vSI.Target = GetShortcutTargetFile(full_name);//fi.IsFolder.ToString();
                //vSI.WindowStyle = "1";
                vSI.WorkingDirectory          = lnk.WorkingDirectory;
                vSI.ShortcutPathSpecialFolder = "Other";

                WshShell    theShell    = new WshShell();
                WshShortcut theShortcut = (WshShortcut)theShell.CreateShortcut(full_name);
                vSI.WindowStyle = frmMain.WindowStyleToInt(theShortcut.WindowStyle);
                vSI.Hotkey      = theShortcut.Hotkey.ToString();

                //name = folder_item.Name;
                //descr = lnk.Description;
                //path = lnk.Path;
                //working_dir = lnk.WorkingDirectory;
                //args = lnk.Arguments;

                return("");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }