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

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


Hi,
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
increment.
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
problem.

    [CustomAction]
    public static ActionResult RegistryDetails(Session session)
    {
        try
        {
            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>();
                subKeyList.AddRange(prnKey.GetSubKeyNames());

                while (subKeyList.Contains(printerIndex.ToString()))
                {
                    printerIndex++;
                }
            }

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

            CurrentSession.Log(ex.Message);
            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