Exemplo n.º 1
0
        public void Dispose(bool disposing)
        {
            lock (this)
            {
                if (!_disposed)
                {
                    try
                    {
                        if (disposing)
                        {
                            // Release managed components
                        }

                        // Release unmanaged components
                        _applicationRegistration = null;

                        // Notify the shell that there has been some changes to the association entries...
                        int SHCNE_ASSOCCHANGED = 0x08000000;
                        int SHCNF_IDLIST       = 0x0000;
                        SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
                    }
                    finally
                    {
                        _disposed = true;
                    }
                }
            }
        }
Exemplo n.º 2
0
        /*
         * companyname:
         *      Describes the name of the company. If no companyname is supplied Application.CompanyName will be used.
         *
         * productname:
         *      Describes the name of the product. If no productname is supplied Application.ProductName will be used.
         *
         * applicationdescription:
         *
         * executable:
         *
         */
        public FileAssociationManager(string companyname, string productname, string applicationdescription, string executable)
        {
            if (string.IsNullOrEmpty(companyname))
            {
                companyname = Application.CompanyName;
            }

            if (string.IsNullOrEmpty(productname))
            {
                productname = Application.ProductName;
            }

            if (string.IsNullOrEmpty(applicationdescription))
            {
                Assembly exeasm = Assembly.GetExecutingAssembly();
                AssemblyDescriptionAttribute desc = (AssemblyDescriptionAttribute)AssemblyDescriptionAttribute.GetCustomAttribute(exeasm, typeof(AssemblyDescriptionAttribute));

                applicationdescription = desc.Description;

                if (string.IsNullOrEmpty(applicationdescription))
                {
                    applicationdescription = Application.ProductName;
                }
            }

            if (string.IsNullOrEmpty(executable))
            {
                executable = Application.ExecutablePath;
            }

            // ***

            if (string.IsNullOrEmpty(companyname))
            {
                throw new Exception("Company name cannot be null or empty!");
            }

            if (string.IsNullOrEmpty(productname))
            {
                throw new Exception("Product name cannot be null or empty!");
            }

            // ***

            _companyName            = companyname;
            _productName            = productname;
            _applicationDescription = applicationdescription;
            _executablePath         = executable;

            if (IsDefaultProgramsAvailable())
            {
                _applicationRegistration = (IApplicationAssociationRegistration) new ApplicationAssociationRegistration();
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            IApplicationAssociationRegistration reg =
                (IApplicationAssociationRegistration) new ApplicationAssociationRegistration();

            string progID;

            reg.QueryCurrentDefault(".txt",
                                    ASSOCIATIONTYPE.AT_FILEEXTENSION,
                                    ASSOCIATIONLEVEL.AL_EFFECTIVE,
                                    out progID);
            Console.WriteLine(progID);

            reg.QueryCurrentDefault("http",
                                    ASSOCIATIONTYPE.AT_URLPROTOCOL,
                                    ASSOCIATIONLEVEL.AL_EFFECTIVE,
                                    out progID);
            Console.WriteLine(progID);
        }
Exemplo n.º 4
0
        /*
         * companyname:
         *      Describes the name of the company. If no companyname is supplied Application.CompanyName will be used.
         *
         * productname:
         *      Describes the name of the product. If no productname is supplied Application.ProductName will be used.
         *
         * applicationdescription:
         *
         * executable:
         *
         */
        public FileAssociationManager(string companyname, string productname, string applicationdescription, string executable)
        {
            if (string.IsNullOrEmpty(companyname))
                companyname = Application.CompanyName;

            if (string.IsNullOrEmpty(productname))
                productname = Application.ProductName;

            if (string.IsNullOrEmpty(applicationdescription))
            {
                Assembly exeasm = Assembly.GetExecutingAssembly();
                AssemblyDescriptionAttribute desc = (AssemblyDescriptionAttribute)AssemblyDescriptionAttribute.GetCustomAttribute(exeasm, typeof(AssemblyDescriptionAttribute));

                applicationdescription = desc.Description;

                if (string.IsNullOrEmpty(applicationdescription))
                {
                    applicationdescription = Application.ProductName;
                }
            }

            if (string.IsNullOrEmpty(executable))
                executable = Application.ExecutablePath;

            // ***

            if (string.IsNullOrEmpty(companyname))
                throw new Exception("Company name cannot be null or empty!");

            if (string.IsNullOrEmpty(productname))
                throw new Exception("Product name cannot be null or empty!");

            // ***

            _companyName = companyname;
            _productName = productname;
            _applicationDescription = applicationdescription;
            _executablePath = executable;

            if (IsDefaultProgramsAvailable())
            {
                _applicationRegistration = (IApplicationAssociationRegistration)new ApplicationAssociationRegistration();
            }
        }
Exemplo n.º 5
0
        public void Dispose(bool disposing)
        {
            lock (this)
            {
                if (!_disposed)
                {
                    try
                    {
                        if (disposing)
                        {
                            // Release managed components
                        }

                        // Release unmanaged components
                        _applicationRegistration = null;

                        // Notify the shell that there has been some changes to the association entries...
                        int SHCNE_ASSOCCHANGED = 0x08000000;
                        int SHCNF_IDLIST = 0x0000;
                        SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
                    }
                    finally
                    {
                        _disposed = true;
                    }
                }
            }
        }