/// <summary>
        /// Return with Explorer registered application by file's extension (for editing)
        /// </summary>
        /// <param name="extension"></param>
        /// <param name="verb"></param>
        /// <returns></returns>
        /// <see cref="http://windevblog.blogspot.com/2008/09/get-default-application-in-windows-xp.html"/>
        /// <see cref="http://msdn.microsoft.com/en-us/library/cc144154%28VS.85%29.aspx"/>
        private string GetExplorerRegisteredApplication(string extension, string verb)
        {
            try
            {
                object obj;
                AssocCreate(CLSID_QueryAssociations, ref IID_IQueryAssociations, out obj);
                IQueryAssociations qa = (IQueryAssociations)obj;
                qa.Init(ASSOCF.INIT_DEFAULTTOSTAR, extension, UIntPtr.Zero, IntPtr.Zero);

                int size = 0;
                qa.GetString(ASSOCF.NOTRUNCATE, ASSOCSTR.COMMAND, verb, null, ref size);

                StringBuilder sb = new StringBuilder(size);
                qa.GetString(ASSOCF.NOTRUNCATE, ASSOCSTR.COMMAND, verb, sb, ref size);

                string cmd = sb.ToString();
                if (Utils.IsBlank(cmd))
                {
                    return(null);
                }

                if (cmd.Contains("\""))
                {
                    return(cmd.Substring(1, cmd.IndexOf("\"", 1) - 1));
                }
                return(cmd.Substring(0, cmd.IndexOf(" ")));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
예제 #2
0
        private string GetString(ASSOCSTR astr)
        {
            const ASSOCF flags = ASSOCF.ASSOCF_NOTRUNCATE | ASSOCF.ASSOCF_REMAPRUNDLL;
            var          sz    = 0U;

            qassoc.GetString(flags, astr, null, null, ref sz);
            var sb = new StringBuilder((int)sz, (int)sz);

            qassoc.GetString(flags, astr, null, sb, ref sz);
            return(sb.ToString());
        }