diff options
| author | Rob Mensching <rob@firegiant.com> | 2018-07-23 21:38:19 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2018-10-02 14:26:42 -0700 |
| commit | 128c46049fb73f18edd248d2a6e80a933cbe2d80 (patch) | |
| tree | c0dad984a9cb078f810a41f1ff1961c93d5cc179 /src | |
| parent | 84d8f809e829f0696006f07997b97f3b6030fcc1 (diff) | |
| download | wix-128c46049fb73f18edd248d2a6e80a933cbe2d80.tar.gz wix-128c46049fb73f18edd248d2a6e80a933cbe2d80.tar.bz2 wix-128c46049fb73f18edd248d2a6e80a933cbe2d80.zip | |
Add support for REG_EXPAND_SZ
Diffstat (limited to 'src')
| -rw-r--r-- | src/dutil/regutil.cpp | 87 |
1 files changed, 60 insertions, 27 deletions
diff --git a/src/dutil/regutil.cpp b/src/dutil/regutil.cpp index ec370f58..1b13af81 100644 --- a/src/dutil/regutil.cpp +++ b/src/dutil/regutil.cpp | |||
| @@ -17,6 +17,13 @@ static PFN_REGDELETEVALUEW vpfnRegDeleteValueW = ::RegDeleteValueW; | |||
| 17 | static HMODULE vhAdvApi32Dll = NULL; | 17 | static HMODULE vhAdvApi32Dll = NULL; |
| 18 | static BOOL vfRegInitialized = FALSE; | 18 | static BOOL vfRegInitialized = FALSE; |
| 19 | 19 | ||
| 20 | static HRESULT WriteStringToRegistry( | ||
| 21 | __in HKEY hk, | ||
| 22 | __in_z_opt LPCWSTR wzName, | ||
| 23 | __in_z_opt LPCWSTR wzValue, | ||
| 24 | __in DWORD dwType | ||
| 25 | ); | ||
| 26 | |||
| 20 | /******************************************************************** | 27 | /******************************************************************** |
| 21 | RegInitialize - initializes regutil | 28 | RegInitialize - initializes regutil |
| 22 | 29 | ||
| @@ -221,7 +228,7 @@ extern "C" HRESULT DAPI RegDelete( | |||
| 221 | while (E_NOMOREITEMS != (hr = RegKeyEnum(hkKey, 0, &pszEnumeratedSubKey))) | 228 | while (E_NOMOREITEMS != (hr = RegKeyEnum(hkKey, 0, &pszEnumeratedSubKey))) |
| 222 | { | 229 | { |
| 223 | ExitOnFailure(hr, "Failed to enumerate key 0"); | 230 | ExitOnFailure(hr, "Failed to enumerate key 0"); |
| 224 | 231 | ||
| 225 | hr = PathConcat(wzSubKey, pszEnumeratedSubKey, &pszRecursiveSubKey); | 232 | hr = PathConcat(wzSubKey, pszEnumeratedSubKey, &pszRecursiveSubKey); |
| 226 | ExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); | 233 | ExitOnFailure(hr, "Failed to concatenate paths while recursively deleting subkeys. Path1: %ls, Path2: %ls", wzSubKey, pszEnumeratedSubKey); |
| 227 | 234 | ||
| @@ -734,6 +741,21 @@ LExit: | |||
| 734 | 741 | ||
| 735 | 742 | ||
| 736 | /******************************************************************** | 743 | /******************************************************************** |
| 744 | RegWriteExpandString - writes a registry key value as an expand string. | ||
| 745 | |||
| 746 | Note: if wzValue is NULL the value will be removed. | ||
| 747 | *********************************************************************/ | ||
| 748 | extern "C" HRESULT DAPI RegWriteExpandString( | ||
| 749 | __in HKEY hk, | ||
| 750 | __in_z_opt LPCWSTR wzName, | ||
| 751 | __in_z_opt LPCWSTR wzValue | ||
| 752 | ) | ||
| 753 | { | ||
| 754 | return WriteStringToRegistry(hk, wzName, wzValue, REG_EXPAND_SZ); | ||
| 755 | } | ||
| 756 | |||
| 757 | |||
| 758 | /******************************************************************** | ||
| 737 | RegWriteString - writes a registry key value as a string. | 759 | RegWriteString - writes a registry key value as a string. |
| 738 | 760 | ||
| 739 | Note: if wzValue is NULL the value will be removed. | 761 | Note: if wzValue is NULL the value will be removed. |
| @@ -744,30 +766,7 @@ extern "C" HRESULT DAPI RegWriteString( | |||
| 744 | __in_z_opt LPCWSTR wzValue | 766 | __in_z_opt LPCWSTR wzValue |
| 745 | ) | 767 | ) |
| 746 | { | 768 | { |
| 747 | HRESULT hr = S_OK; | 769 | return WriteStringToRegistry(hk, wzName, wzValue, REG_SZ); |
| 748 | DWORD er = ERROR_SUCCESS; | ||
| 749 | DWORD cbValue = 0; | ||
| 750 | |||
| 751 | if (wzValue) | ||
| 752 | { | ||
| 753 | hr = ::StringCbLengthW(wzValue, DWORD_MAX, reinterpret_cast<size_t*>(&cbValue)); | ||
| 754 | ExitOnFailure(hr, "Failed to determine length of registry value: %ls", wzName); | ||
| 755 | |||
| 756 | er = vpfnRegSetValueExW(hk, wzName, 0, REG_SZ, reinterpret_cast<const BYTE *>(wzValue), cbValue); | ||
| 757 | ExitOnWin32Error(er, hr, "Failed to set registry value: %ls", wzName); | ||
| 758 | } | ||
| 759 | else | ||
| 760 | { | ||
| 761 | er = vpfnRegDeleteValueW(hk, wzName); | ||
| 762 | if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) | ||
| 763 | { | ||
| 764 | er = ERROR_SUCCESS; | ||
| 765 | } | ||
| 766 | ExitOnWin32Error(er, hr, "Failed to delete registry value: %ls", wzName); | ||
| 767 | } | ||
| 768 | |||
| 769 | LExit: | ||
| 770 | return hr; | ||
| 771 | } | 770 | } |
| 772 | 771 | ||
| 773 | 772 | ||
| @@ -791,7 +790,7 @@ extern "C" HRESULT DAPI RegWriteStringFormatted( | |||
| 791 | va_end(args); | 790 | va_end(args); |
| 792 | ExitOnFailure(hr, "Failed to allocate %ls value.", wzName); | 791 | ExitOnFailure(hr, "Failed to allocate %ls value.", wzName); |
| 793 | 792 | ||
| 794 | hr = RegWriteString(hk, wzName, sczValue); | 793 | hr = WriteStringToRegistry(hk, wzName, sczValue, REG_SZ); |
| 795 | 794 | ||
| 796 | LExit: | 795 | LExit: |
| 797 | ReleaseStr(sczValue); | 796 | ReleaseStr(sczValue); |
| @@ -845,7 +844,7 @@ HRESULT DAPI RegWriteStringArray( | |||
| 845 | { | 844 | { |
| 846 | hr = ::StringCchCopyW(wzCopyDestination, dwTotalStringSize, rgwzValues[i]); | 845 | hr = ::StringCchCopyW(wzCopyDestination, dwTotalStringSize, rgwzValues[i]); |
| 847 | ExitOnFailure(hr, "failed to copy string: %ls", rgwzValues[i]); | 846 | ExitOnFailure(hr, "failed to copy string: %ls", rgwzValues[i]); |
| 848 | 847 | ||
| 849 | dwTemp -= lstrlenW(rgwzValues[i]) + 1; | 848 | dwTemp -= lstrlenW(rgwzValues[i]) + 1; |
| 850 | wzCopyDestination += lstrlenW(rgwzValues[i]) + 1; | 849 | wzCopyDestination += lstrlenW(rgwzValues[i]) + 1; |
| 851 | } | 850 | } |
| @@ -924,3 +923,37 @@ extern "C" HRESULT DAPI RegQueryKey( | |||
| 924 | LExit: | 923 | LExit: |
| 925 | return hr; | 924 | return hr; |
| 926 | } | 925 | } |
| 926 | |||
| 927 | |||
| 928 | static HRESULT WriteStringToRegistry( | ||
| 929 | __in HKEY hk, | ||
| 930 | __in_z_opt LPCWSTR wzName, | ||
| 931 | __in_z_opt LPCWSTR wzValue, | ||
| 932 | __in DWORD dwType | ||
| 933 | ) | ||
| 934 | { | ||
| 935 | HRESULT hr = S_OK; | ||
| 936 | DWORD er = ERROR_SUCCESS; | ||
| 937 | DWORD cbValue = 0; | ||
| 938 | |||
| 939 | if (wzValue) | ||
| 940 | { | ||
| 941 | hr = ::StringCbLengthW(wzValue, DWORD_MAX, reinterpret_cast<size_t*>(&cbValue)); | ||
| 942 | ExitOnFailure(hr, "Failed to determine length of registry value: %ls", wzName); | ||
| 943 | |||
| 944 | er = vpfnRegSetValueExW(hk, wzName, 0, dwType, reinterpret_cast<const BYTE *>(wzValue), cbValue); | ||
| 945 | ExitOnWin32Error(er, hr, "Failed to set registry value: %ls", wzName); | ||
| 946 | } | ||
| 947 | else | ||
| 948 | { | ||
| 949 | er = vpfnRegDeleteValueW(hk, wzName); | ||
| 950 | if (ERROR_FILE_NOT_FOUND == er || ERROR_PATH_NOT_FOUND == er) | ||
| 951 | { | ||
| 952 | er = ERROR_SUCCESS; | ||
| 953 | } | ||
| 954 | ExitOnWin32Error(er, hr, "Failed to delete registry value: %ls", wzName); | ||
| 955 | } | ||
| 956 | |||
| 957 | LExit: | ||
| 958 | return hr; | ||
| 959 | } | ||
