Windows setup: dynamic registry keys / values

A brief description of my question:

Can I use my own custom user variables (the way you can use [TARGETDIR]) on the registry screen of the Windows Setup project in VS2010? In particular, I need to save my strong assembly name and assembly version in the registry in order to register a COM object on a machine without an installed user with administrator rights.

I have already tried using a custom action, and I would prefer not to continue this way if possible.

Here are the specifics and what I tried:

Recently, my employer began to blindly remove the rights of all employees from their computers.

I created a C # class that is open to COM, which I used on several of my workstations, which can no longer be registered because I no longer have the appropriate permissions in HKEY_CLASSES_ROOT.

Through Googling, I learned how to register all the relevant keys under HKCU *, but now I would like to implement this in my deployment project.

I understand how to use the registry screen in Windows Setup, but there are special keys / values ​​that need to be saved (set folder, assembly name, version).

, , Windows , () , / , () , , () // Microsoft, .

VS2008 , VS2010, , , - 2008 2010 , .

, , , ?

: , , , Windows "" , , . , MSI (Orca), , .

2: , - ; :


* RegAsm - /codebase ; /regfile. ( ) HKCR HKCU\Software\Classes.

+3
1

, *.

Console, Windows. Registry MSI, VS2010.

. " Microsoft Windows" COM, .

using System;
using WindowsInstaller;
using System.Runtime.InteropServices;
using System.Reflection;

namespace Post_Setup_Scripting
{
    class Program
    {

        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Incorrect args.");
                return;
            }

            //arg 1 - path to MSI
            string PathToMSI = args[0];
            //arg 2 - path to assembly
            string PathToAssembly = args[1];

            Type InstallerType;
            WindowsInstaller.Installer Installer;
            InstallerType = Type.GetTypeFromProgID("WindowsInstaller.Installer");
            Installer = (WindowsInstaller.Installer)Activator.CreateInstance(InstallerType);

            Assembly Assembly = Assembly.LoadFrom(PathToAssembly);
            string AssemblyStrongName = Assembly.GetName().FullName;
            string AssemblyVersion = Assembly.GetName().Version.ToString();

            string SQL = "SELECT `Key`, `Name`, `Value` FROM `Registry`";
            WindowsInstaller.Database Db = Installer.OpenDatabase(PathToMSI, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeDirect);
            WindowsInstaller.View View = Db.OpenView(SQL);
            View.Execute();
            WindowsInstaller.Record Rec = View.Fetch();
            while (Rec != null)
            {
                for (int c = 0; c <= Rec.FieldCount; c++)
                {
                    string Column = Rec.get_StringData(c);
                    Column = Column.Replace("[AssemblyVersion]", AssemblyVersion);
                    Column = Column.Replace("[AssemblyStrongName]", AssemblyStrongName);
                    Rec.set_StringData(c, Column);
                    View.Modify(MsiViewModify.msiViewModifyReplace, Rec);
                    Console.Write("{0}\t", Column);
                    Db.Commit();
                }
                Console.WriteLine();
                Rec = View.Fetch();
            }
            View.Close();

            GC.Collect();
            Marshal.FinalReleaseComObject(Installer);

            Console.ReadLine();
        }
    }
}

"", Windows Setup, ; , .

string Column = Rec.get_StringData(c);
Column = Column.Replace("[AssemblyVersion]", AssemblyVersion);
Column = Column.Replace("[AssemblyStrongName]", AssemblyStrongName);

-, REG , , . MSI -, [AssemblyVersion] [AssemblyStrongName] .

[HKEY_CURRENT_USER\Software\Classes\Record\{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}\[AssemblyVersion]]
"Class"="MyClass.MyClass"
"Assembly"="[AssemblyStrongName]"
"RuntimeVersion"="v2.0.50727"
"CodeBase"="[TARGETDIR]MyClass.dll"

-, .reg Windows Setup VS2010, " " "".

, post-build "PostBuildEvent" :

"C:\Path\To\Exe\Post-Setup Scripting.exe" [Path to MSI] [Path To DLL to extract strong name/version]

* [TARGETDIR], [TARGETDIR] , "" . , .

+1

Source: https://habr.com/ru/post/1723962/


All Articles