1

There's a registry key under HKML that contains a comma-separated list of drivers to load.

HKLM\Somewhere "InstalledDrivers" "foo,bar"

When installing our driver, we need to append an entry to this list so it becomes

HKLM\Somewhere "InstalledDrivers" "foo,bar,baz"

and on uninstall we need to pull just our entry away from the list, i.e. do a s/,baz// so it returns to it's original state

HKLM\Somewhere "InstalledDrivers" "foo,bar"

I can't just store the key on install and remove it on uninstall, because if other drivers get installed, the key might be "foo,bar,baz,bravo" - so it should become "foo,bar,bravo" after our driver gets uninstalled.

Oh and if ,baz is already in the list, it should not be added again.

How on earth do I wrestle WiX to manipulate keys like this?

lwa
  • 91
  • 9
  • **I am unfamiliar with that key, can we ask its exact location in the registry?** A key like that should be updated via some sort of API that you should just call to do the job? When I run [autoruns.exe](https://learn.microsoft.com/en-us/sysinternals/downloads/autoruns) from System Internals the driver list to enable / disable drivers from is at: `HKLM\SYSTEM\CurrentControlSet\Services` as sub keys. And [for the record on driver installation](https://stackoverflow.com/a/51845307/129130) – Stein Åsmul Dec 19 '20 at 03:55
  • The exact location is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Citrix\ICA Client\Engine\Configuration\Advanced\Modules\ICA 3.0\VirtualDriver – lwa Dec 19 '20 at 20:32
  • OK, that must be some Terminal Server stuff that I haven't seen before. I have added an answer below on how to do this string parsing. Are you familiar with how to use C# custom actions? – Stein Åsmul Dec 20 '20 at 17:58
  • There is a WiX sample of C# deferred mode custom actions here: https://github.com/glytzhkof/WiXDeferredModeSample – Stein Åsmul Dec 20 '20 at 18:19

2 Answers2

0

MSI/WiX only support appending/prepending multistring registry values. What you describe is a comma delimited string.

You would need to use AppSearch to read the existing value into a property. Use a custom action to format the property the way you desire and then use WiX to write the registry value back out.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
-1

There might be better ways, but using C# you could do something like this.

Here is a C# 2019 sample:

using System;
using System.Collections.Generic;
using System.Linq;

namespace CommaSeparatedEditing
{
    class Program
    {
        static void Main(string[] args)
        {
            var list = "foo, bar, baz, stack, overflow, server, fault,endingentry";

            List<String> Items = list.Split(',').Select(i => i.Trim()).Where(i => i != string.Empty).ToList(); // Split them all and remove spaces
            Items.Remove("fault"); // Remove any value you want
            Items.Add("My New Entry"); // Add a new entry

            string modifiedlist = String.Join(", ", Items.ToArray());

            Console.WriteLine(modifiedlist);
            Console.ReadLine(); // keep console open to show result
        }
    }
}

The above uses a typed list / generic collection from the System.Collections.Generic namespace. There are many other approaches by using more light weight string arrays, regex and replace commands that search for a specific entry and replace it with a blank space: "".

Here are some sample snippets of some alternative ways: How do I remove comma separated specific value from a string? (scroll down the page).

There is a WiX sample of C# deferred mode custom actions here: https://www.github.com/glytzhkof/WiXDeferredModeSample

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164