最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Wix write byte array binary value to registry - Stack Overflow

programmeradmin2浏览0评论

I am trying to write a password string that is converted to a byte array by some algorithm to the registry where the type is reg_binary using Wix. But when doing so, I get an error as below: I am running the installer as an admin.

This is what I have. The variables are declared as follows, I can see DSN and UID in the registry after installing. But for PWD, the installer is giving an error as below.

<Property Id="DBDSN" Secure="yes" Value="PharmSpec_DSN"/>
        <Property Id="DBUID" Secure="yes"  Value="PharmSpecUsr"/>
        <Property Id="DBPWD" Secure="yes" Hidden="yes" Value="220,65,202,153,221,86,197,178,212,16,105,233,16,129,21,97,151,207,163,60,183,45,111,47"/>
    

    <Component Id="RegistryEntries_PharmSpec_ManualConfig" Guid="1C6A6F76-3898-40DE-AC0C-F7A59BECB471" KeyPath="yes" Directory="INSTALLDIR" Win64='yes'>
            <!--<Condition>
                <![CDATA[(WIX_UPGRADE_DETECTED) AND (DBDSN<>"-|-") AND (DBUID<>"-|-") AND (DBPWD<>"-|-")]]>
            </Condition>-->
            <RegistryKey Root="HKLM" Key="SOFTWARE\$(var.Manufacturer)" >
                <RegistryKey Key ="PharmSpec" Id="PharmSpec_Key4" ForceCreateOnInstall="yes">
                    <RegistryKey Key="Database" Id ="Database_Key4" ForceCreateOnInstall="yes">
                        <util:PermissionEx User="Users" GenericAll="yes"/>
                        <RegistryValue Name="DSN" Value="[DBDSN]" Type="string" Action='write'/>
                        <RegistryValue Name="UID" Value="[DBUID]" Type="string" Action="write"/>
                        <RegistryValue Name="PWD" Value="[DBPWD]" Type="binary" Action="write"/>
                    </RegistryKey>
                </RegistryKey>
            </RegistryKey>
        </Component>

The component is referred as,

<Feature Id='Complete' Title='$(var.ProductFullName)' Description='!(loc.IDPROP_SETUPTYPE_COMPLETE_DESC)' Display='expand' Level='1' >
<ComponentRef Id='RegistryEntries_PharmSpec_ManualConfig' />
</Feature>

When running the installer, I get an error as follows,

If I click Ignore, the product is installed and in the registry, I can see DSN and UID without PWD. Please help.

If I try the same in a C# app, it writes the password in the registry as reg_binary (please see the byPassword). I want to do the same in Wix.

public static bool WriteDatabaseInfoToRegistry(string szUserName, string szPassword, string szDSN)
        {
            bool bSuccess = false;
            byte[] byPassword = null;

            try
            {
                //Write the information to the registry
                Registry.SetValue(PHARMSPEC_REGISTRY_KEY, "UID", szUserName);
                Registry.SetValue(PHARMSPEC_REGISTRY_KEY, "DSN", szDSN);
                if (HUATripleDES.Encrypt(szPassword, out byPassword) == true)
                {
                    Registry.SetValue(PHARMSPEC_REGISTRY_KEY, "PWD", byPassword);
                    bSuccess = true;
                }
            }
            catch (Exception ex)
            {
                bSuccess = false;
                throw ex;
            }

            return bSuccess;
        }

Edit

I tried converting byte array to hex string and modified the property like follows: but still it's giving the same error.

<Variable Name="Dbpwd" Value="DC-41-CA-99-DD-56-C5-B2-D4-10-69-E9-10-81-15-61-97-CF-A3-3C-B7-2D-6F-2F"/>

I am trying to write a password string that is converted to a byte array by some algorithm to the registry where the type is reg_binary using Wix. But when doing so, I get an error as below: I am running the installer as an admin.

This is what I have. The variables are declared as follows, I can see DSN and UID in the registry after installing. But for PWD, the installer is giving an error as below.

<Property Id="DBDSN" Secure="yes" Value="PharmSpec_DSN"/>
        <Property Id="DBUID" Secure="yes"  Value="PharmSpecUsr"/>
        <Property Id="DBPWD" Secure="yes" Hidden="yes" Value="220,65,202,153,221,86,197,178,212,16,105,233,16,129,21,97,151,207,163,60,183,45,111,47"/>
    

    <Component Id="RegistryEntries_PharmSpec_ManualConfig" Guid="1C6A6F76-3898-40DE-AC0C-F7A59BECB471" KeyPath="yes" Directory="INSTALLDIR" Win64='yes'>
            <!--<Condition>
                <![CDATA[(WIX_UPGRADE_DETECTED) AND (DBDSN<>"-|-") AND (DBUID<>"-|-") AND (DBPWD<>"-|-")]]>
            </Condition>-->
            <RegistryKey Root="HKLM" Key="SOFTWARE\$(var.Manufacturer)" >
                <RegistryKey Key ="PharmSpec" Id="PharmSpec_Key4" ForceCreateOnInstall="yes">
                    <RegistryKey Key="Database" Id ="Database_Key4" ForceCreateOnInstall="yes">
                        <util:PermissionEx User="Users" GenericAll="yes"/>
                        <RegistryValue Name="DSN" Value="[DBDSN]" Type="string" Action='write'/>
                        <RegistryValue Name="UID" Value="[DBUID]" Type="string" Action="write"/>
                        <RegistryValue Name="PWD" Value="[DBPWD]" Type="binary" Action="write"/>
                    </RegistryKey>
                </RegistryKey>
            </RegistryKey>
        </Component>

The component is referred as,

<Feature Id='Complete' Title='$(var.ProductFullName)' Description='!(loc.IDPROP_SETUPTYPE_COMPLETE_DESC)' Display='expand' Level='1' >
<ComponentRef Id='RegistryEntries_PharmSpec_ManualConfig' />
</Feature>

When running the installer, I get an error as follows,

If I click Ignore, the product is installed and in the registry, I can see DSN and UID without PWD. Please help.

If I try the same in a C# app, it writes the password in the registry as reg_binary (please see the byPassword). I want to do the same in Wix.

public static bool WriteDatabaseInfoToRegistry(string szUserName, string szPassword, string szDSN)
        {
            bool bSuccess = false;
            byte[] byPassword = null;

            try
            {
                //Write the information to the registry
                Registry.SetValue(PHARMSPEC_REGISTRY_KEY, "UID", szUserName);
                Registry.SetValue(PHARMSPEC_REGISTRY_KEY, "DSN", szDSN);
                if (HUATripleDES.Encrypt(szPassword, out byPassword) == true)
                {
                    Registry.SetValue(PHARMSPEC_REGISTRY_KEY, "PWD", byPassword);
                    bSuccess = true;
                }
            }
            catch (Exception ex)
            {
                bSuccess = false;
                throw ex;
            }

            return bSuccess;
        }

Edit

I tried converting byte array to hex string and modified the property like follows: but still it's giving the same error.

<Variable Name="Dbpwd" Value="DC-41-CA-99-DD-56-C5-B2-D4-10-69-E9-10-81-15-61-97-CF-A3-3C-B7-2D-6F-2F"/>
Share Improve this question edited Feb 9 at 22:24 halfer 20.3k19 gold badges109 silver badges202 bronze badges asked Jan 29 at 10:20 nikhilnikhil 1,7483 gold badges26 silver badges62 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Off the top of my head, I'm pretty sure this code here:

<util:PermissionEx User="Users" GenericAll="yes"/>

Is only granting access to logged in users to the registry key. The Windows Installer runs as SYSTEM so it doesn't end up with permissions to write to the key. Try granting all rights to SYSTEM, too.

发布评论

评论列表(0)

  1. 暂无评论