[wix-users] Custom action cannot access registry key for read

Mahesh Wickramasinghe wickramasingha4u at gmail.com
Thu Oct 19 19:20:19 PDT 2017

I need a help with this custom action.

I have a custom action which reads registry entry. If the
`session["UtillRegKey"]` already have on registry, `printerIndex` should
The problem is even the registry already have, `prnKey` always become null.
I don't think for reading registry is not required the permission, but even
after sets the permission also the result was same. And then I created a
windows form application, and add the same function there, and it works as
I expected.

Can anyone explain why this `prnKey = prnKey.OpenSubKey(registryPath,
false);` gives null with WIX custom action. and how can i overcome this

    public static ActionResult RegistryDetails(Session session)
            string registryPath = session["UtillRegKey"];
            int printerIndex = 1;
            RegistryKey prnKey = Registry.LocalMachine;
            prnKey = prnKey.OpenSubKey(registryPath, false);

            if (null != prnKey)
                global::System.Windows.Forms.MessageBox.Show("Not NUll");
                List<string> subKeyList = new List<string>();

                while (subKeyList.Contains(printerIndex.ToString()))

            string newRegistryPath = registryPath + "\\" +
            session["UtillRegKey"] = newRegistryPath;
            session["PrinterNo"] = printerIndex.ToString();
        catch (Exception ex)

            Record exceptionRec = new Record(0);
            exceptionRec[0] = "Errors -" + ex.StackTrace.ToString();
            CurrentSession.Message(InstallMessage.Error, exceptionRec);

            return ActionResult.Failure;
        return ActionResult.Success;

More information about the wix-users mailing list