Exemple #1
0
        private static bool isAssociatedVista(string Extension)
        {
            try
            {
                bool res = false;

                IApplicationAssociationRegistration aar;
                if ((aar = new ApplicationAssociationRegistration() as IApplicationAssociationRegistration) != null)
                {
                    aar.QueryAppIsDefault(Extension,
                                          ASSOCIATIONTYPE.AT_FILEEXTENSION,
                                          ASSOCIATIONLEVEL.AL_EFFECTIVE,
                                          "QuuxPlayer",
                                          ref res);

                    return(res);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                return(false);
            }
        }
Exemple #2
0
        private static string associatedProgramVista(string Extension)
        {
            try
            {
                IApplicationAssociationRegistration aar;
                if ((aar = new ApplicationAssociationRegistration() as IApplicationAssociationRegistration) != null)
                {
                    StringBuilder progID = new StringBuilder();

                    Int32 result = aar.QueryCurrentDefault(Extension,
                                                           ASSOCIATIONTYPE.AT_FILEEXTENSION,
                                                           ASSOCIATIONLEVEL.AL_EFFECTIVE,
                                                           ref progID);

                    return(progID.ToString());
                }
                else
                {
                    return(String.Empty);
                }
            }
            catch
            {
                return(String.Empty);
            }
        }
        private void GetDefaultBrowserProgId(out string defaultBrowserProgId)
        {
            try
            {
                // midl "C:\Program Files (x86)\Windows Kits\8.1\Include\um\ShObjIdl.idl"
                // tlbimp ShObjIdl.tlb
                var applicationAssociationRegistration = new ApplicationAssociationRegistration();
                applicationAssociationRegistration.QueryCurrentDefault("http", ASSOCIATIONTYPE.AT_URLPROTOCOL, ASSOCIATIONLEVEL.AL_EFFECTIVE, out defaultBrowserProgId);
            }
            catch (COMException e)
            {
                defaultBrowserProgId = null;
                ThrowTerminatingError(new ErrorRecord(e, e.Message, ErrorCategory.NotSpecified, "http"));
            }

            if (string.IsNullOrEmpty(defaultBrowserProgId))
                ThrowTerminatingError(new ErrorRecord(new Exception("GetDefaultBrowserProgId"), "Unknown ProgID", ErrorCategory.NotSpecified, "http"));
        }
Exemple #4
0
        private static void setAssociationVista(bool Associate, string ProgramID, string Extension)
        {
            try
            {
                IApplicationAssociationRegistration aar;

                if ((aar = new ApplicationAssociationRegistration() as IApplicationAssociationRegistration) != null)
                {
                    if (Associate)
                    {
                        string current = associatedProgramVista(Extension);

                        if (current != ProgramID && current != "QuuxPlayer")
                        {
                            RegistryKey root = HKCU_S_C;
                            RegistryKey k4   = GetRegKey(root, Extension, true);
                            k4.SetValue("QuuxBackup", current, RegistryValueKind.String);
                        }
                        aar.SetAppAsDefault("QuuxPlayer",
                                            Extension,
                                            ASSOCIATIONTYPE.AT_FILEEXTENSION);
                    }
                    else
                    {
                        RegistryKey root    = HKCU_S_C;
                        RegistryKey k4      = GetRegKey(root, Extension, true);
                        string      restore = GetRegValue(k4, "QuuxBackup");

                        if (restore.Length > 0)
                        {
                            aar.SetAppAsDefault(restore,
                                                Extension,
                                                ASSOCIATIONTYPE.AT_FILEEXTENSION);
                        }
                    }
                }
            }
            catch
            {
            }
        }