// assemblyName has to be fully specified name.
        // A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        // For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        // If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        /// <summary>
        /// Uninstalls the assembly.
        /// </summary>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="reference">The reference.</param>
        /// <param name="disp">The disp.</param>
        public static void UninstallAssembly(String assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            int hr = Utils.CreateAssemblyCache(out ac, 0);

            if (hr >= 0)
            {
                hr = ac.UninstallAssembly(0, assemblyName, reference, out dispResult);
            }

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            disp = dispResult;
        }
            /// <summary>
            /// Get next reference.
            /// </summary>
            /// <returns>The install reference.</returns>
            public InstallReference GetNextReference()
            {
                IInstallReferenceItem item = null;
                int hr = refEnum.GetNextInstallReferenceItem(out item, 0, IntPtr.Zero);

                if ((uint)hr == 0x80070103)
                {   // ERROR_NO_MORE_ITEMS
                    return(null);
                }

                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                IntPtr           refData;
                InstallReference instRef = new InstallReference(Guid.Empty, String.Empty, String.Empty);

                hr = item.GetReference(out refData, 0, IntPtr.Zero);
                if (hr < 0)
                {
                    Marshal.ThrowExceptionForHR(hr);
                }

                Marshal.PtrToStructure(refData, instRef);
                return(instRef);
            }
        /// <summary>
        /// Installs the assembly.
        /// </summary>
        /// <param name="assemblyPath">The assembly path.</param>
        /// <param name="reference">The reference.</param>
        /// <param name="flags">The flags.</param>
        /// <returns></returns>
        public static int InstallAssembly(String assemblyPath, InstallReference reference, AssemblyCommitFlags flags)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            int hr = 0;

            hr = Utils.CreateAssemblyCache(out ac, 0);
            if (hr >= 0)
            {
                hr = ac.InstallAssembly((int)flags, assemblyPath, reference);
            }

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
            return(hr);
        }
Exemplo n.º 4
0
 internal AssemblyReference(string assemblyName, InstallReference installRef)
 {
     if (installRef.GuidScheme == InstallReferenceGuid.OpaqueGuid)
         this.OpaqueID = installRef.Identifier;
     else if (installRef.GuidScheme == InstallReferenceGuid.FilePathGuid)
         this.FilePath = installRef.Identifier;
     else if (installRef.GuidScheme == InstallReferenceGuid.UninstallSubkeyGuid)
         this.InstalledApplicationID = installRef.Identifier;
     this.assembly = assemblyName;
     this.installReference = installRef;
 }
        public UninstallDisposition Uninstall(string assemblyName, InstallReference objRef)
        {
            IntPtr pRef = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Fusion.FUSION_INSTALL_REFERENCE)));

            Marshal.StructureToPtr((Fusion.FUSION_INSTALL_REFERENCE)objRef, pRef, false);
            try
            {
                return(Uninstall(assemblyName, pRef));
            }
            finally
            {
                Marshal.DestroyStructure(pRef, typeof(Fusion.FUSION_INSTALL_REFERENCE));

                Marshal.FreeCoTaskMem(pRef);
            }
        }
        public void Install(string fileName, InstallReference objRef)
        {
            IntPtr pRef = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(Fusion.FUSION_INSTALL_REFERENCE)));

            Marshal.StructureToPtr((Fusion.FUSION_INSTALL_REFERENCE)objRef, pRef, false);
            try
            {
                Install(fileName, pRef);
            }
            finally
            {
                Marshal.DestroyStructure(pRef, typeof(Fusion.FUSION_INSTALL_REFERENCE));

                Marshal.FreeCoTaskMem(pRef);
            }
        }
Exemplo n.º 7
0
 internal AssemblyReference(string assemblyName, InstallReference installRef)
 {
     if (installRef.GuidScheme == InstallReferenceGuid.OpaqueGuid)
     {
         this.OpaqueID = installRef.Identifier;
     }
     else if (installRef.GuidScheme == InstallReferenceGuid.FilePathGuid)
     {
         this.FilePath = installRef.Identifier;
     }
     else if (installRef.GuidScheme == InstallReferenceGuid.UninstallSubkeyGuid)
     {
         this.InstalledApplicationID = installRef.Identifier;
     }
     this.assembly         = assemblyName;
     this.installReference = installRef;
 }