Example #1
0
        public static string GetDefaultProgramPathRelated(string Path)
        {
            for (uint BufferSize = 512; ; BufferSize += 512)
            {
                StringBuilder Builder = new StringBuilder(Convert.ToInt32(BufferSize));

                HRESULT Result = ShlwApi.AssocQueryString(ShlwApi.ASSOCF.ASSOCF_NOFIXUPS | ShlwApi.ASSOCF.ASSOCF_VERIFY | ShlwApi.ASSOCF.ASSOCF_NOTRUNCATE | ShlwApi.ASSOCF.ASSOCF_INIT_DEFAULTTOSTAR | ShlwApi.ASSOCF.ASSOCF_REMAPRUNDLL, ShlwApi.ASSOCSTR.ASSOCSTR_EXECUTABLE | ShlwApi.ASSOCSTR.ASSOCSTR_APPID, System.IO.Path.GetExtension(Path).ToLower(), null, Builder, ref BufferSize);

                if (Result == HRESULT.S_OK)
                {
                    string ExePath = Builder.ToString();

                    if (System.IO.Path.IsPathRooted(ExePath))
                    {
                        return(ExePath);
                    }
                    else
                    {
                        return(ExePath.Replace("@", string.Empty).Replace("{", string.Empty).Replace("}", string.Empty).Split('?').FirstOrDefault());
                    }
                }
                else if (Result == HRESULT.E_POINTER)
                {
                    continue;
                }
                else
                {
                    return(string.Empty);
                }
            }
        }
Example #2
0
        public static string GetAssociate(string Path)
        {
            Task <string> RunTask = Task.Run(() =>
            {
                try
                {
                    uint Length = 0;

                    if (ShlwApi.AssocQueryString(ShlwApi.ASSOCF.ASSOCF_NOFIXUPS | ShlwApi.ASSOCF.ASSOCF_VERIFY, ShlwApi.ASSOCSTR.ASSOCSTR_EXECUTABLE, System.IO.Path.GetExtension(Path), null, null, ref Length) == HRESULT.S_FALSE)
                    {
                        StringBuilder Builder = new StringBuilder((int)Length);

                        if (ShlwApi.AssocQueryString(ShlwApi.ASSOCF.ASSOCF_NOFIXUPS | ShlwApi.ASSOCF.ASSOCF_VERIFY, ShlwApi.ASSOCSTR.ASSOCSTR_EXECUTABLE, System.IO.Path.GetExtension(Path), null, Builder, ref Length) == HRESULT.S_OK)
                        {
                            return(Builder.ToString());
                        }
                        else
                        {
                            return(string.Empty);
                        }
                    }
                    else
                    {
                        return(string.Empty);
                    }
                }
                catch
                {
                    return(string.Empty);
                }
            });

            if (SpinWait.SpinUntil(() => RunTask.IsCompleted, 3000))
            {
                return(RunTask.Result);
            }
            else
            {
                return(string.Empty);
            }
        }