📄 registry.c
字号:
LPWSTR msi_reg_get_val_str( HKEY hkey, LPCWSTR name )
{
DWORD len = 0;
LPWSTR val;
LONG r;
r = RegQueryValueExW(hkey, name, NULL, NULL, NULL, &len);
if (r != ERROR_SUCCESS)
return NULL;
len += sizeof (WCHAR);
val = msi_alloc( len );
if (!val)
return NULL;
val[0] = 0;
RegQueryValueExW(hkey, name, NULL, NULL, (LPBYTE) val, &len);
return val;
}
BOOL msi_reg_get_val_dword( HKEY hkey, LPCWSTR name, DWORD *val)
{
DWORD type, len = sizeof (DWORD);
LONG r = RegQueryValueExW(hkey, name, NULL, &type, (LPBYTE) val, &len);
return r == ERROR_SUCCESS && type == REG_DWORD;
}
UINT MSIREG_OpenUninstallKey(LPCWSTR szProduct, HKEY* key, BOOL create)
{
UINT rc;
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szProduct));
sprintfW(keypath,szUninstall_fmt,szProduct);
if (create)
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, keypath, key);
else
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE, keypath, key);
return rc;
}
UINT MSIREG_OpenUserProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szProduct));
squash_guid(szProduct,squished_pc);
TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath,szUserProduct_fmt,squished_pc);
if (create)
rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
else
rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
return rc;
}
UINT MSIREG_OpenUserFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szProduct));
squash_guid(szProduct,squished_pc);
TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath,szUserFeatures_fmt,squished_pc);
if (create)
rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
else
rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
return rc;
}
UINT MSIREG_OpenFeatures(HKEY* key)
{
return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Features,key);
}
UINT MSIREG_OpenFeaturesKey(LPCWSTR szProduct, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szProduct));
squash_guid(szProduct,squished_pc);
TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath,szInstaller_Features_fmt,squished_pc);
if (create)
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
else
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
return rc;
}
UINT MSIREG_OpenComponents(HKEY* key)
{
return RegCreateKeyW(HKEY_LOCAL_MACHINE,szInstaller_Components,key);
}
UINT MSIREG_OpenComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_cc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szComponent));
squash_guid(szComponent,squished_cc);
TRACE("squished (%s)\n", debugstr_w(squished_cc));
sprintfW(keypath,szInstaller_Components_fmt,squished_cc);
if (create)
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
else
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
return rc;
}
UINT MSIREG_OpenUserComponentsKey(LPCWSTR szComponent, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_cc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szComponent));
squash_guid(szComponent,squished_cc);
TRACE("squished (%s)\n", debugstr_w(squished_cc));
sprintfW(keypath,szUser_Components_fmt,squished_cc);
if (create)
rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
else
rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
return rc;
}
UINT MSIREG_OpenProductsKey(LPCWSTR szProduct, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szProduct));
squash_guid(szProduct,squished_pc);
TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath,szInstaller_Products_fmt,squished_pc);
if (create)
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
else
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
return rc;
}
UINT MSIREG_OpenUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szUpgradeCode));
squash_guid(szUpgradeCode,squished_pc);
TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath,szInstaller_UpgradeCodes_fmt,squished_pc);
if (create)
rc = RegCreateKeyW(HKEY_LOCAL_MACHINE,keypath,key);
else
rc = RegOpenKeyW(HKEY_LOCAL_MACHINE,keypath,key);
return rc;
}
UINT MSIREG_OpenUserUpgradeCodesKey(LPCWSTR szUpgradeCode, HKEY* key, BOOL create)
{
UINT rc;
WCHAR squished_pc[GUID_SIZE];
WCHAR keypath[0x200];
TRACE("%s\n",debugstr_w(szUpgradeCode));
squash_guid(szUpgradeCode,squished_pc);
TRACE("squished (%s)\n", debugstr_w(squished_pc));
sprintfW(keypath,szInstaller_UserUpgradeCodes_fmt,squished_pc);
if (create)
rc = RegCreateKeyW(HKEY_CURRENT_USER,keypath,key);
else
rc = RegOpenKeyW(HKEY_CURRENT_USER,keypath,key);
return rc;
}
/*************************************************************************
* MsiDecomposeDescriptorW [MSI.@]
*
* Decomposes an MSI descriptor into product, feature and component parts.
* An MSI descriptor is a string of the form:
* [base 85 guid] [feature code] '>' [base 85 guid]
*
* PARAMS
* szDescriptor [I] the descriptor to decompose
* szProduct [O] buffer of MAX_FEATURE_CHARS+1 for the product guid
* szFeature [O] buffer of MAX_FEATURE_CHARS+1 for the feature code
* szComponent [O] buffer of MAX_FEATURE_CHARS+1 for the component guid
* pUsed [O] the length of the descriptor
*
* RETURNS
* ERROR_SUCCESS if everything worked correctly
* ERROR_INVALID_PARAMETER if the descriptor was invalid
*
*/
UINT WINAPI MsiDecomposeDescriptorW( LPCWSTR szDescriptor, LPWSTR szProduct,
LPWSTR szFeature, LPWSTR szComponent, DWORD *pUsed )
{
UINT r, len;
LPWSTR p;
GUID product, component;
TRACE("%s %p %p %p %p\n", debugstr_w(szDescriptor), szProduct,
szFeature, szComponent, pUsed);
r = decode_base85_guid( szDescriptor, &product );
if( !r )
return ERROR_INVALID_PARAMETER;
TRACE("product %s\n", debugstr_guid( &product ));
p = strchrW(&szDescriptor[20],'>');
if( !p )
return ERROR_INVALID_PARAMETER;
len = (p - &szDescriptor[20]);
if( len > MAX_FEATURE_CHARS )
return ERROR_INVALID_PARAMETER;
TRACE("feature %s\n", debugstr_wn( &szDescriptor[20], len ));
r = decode_base85_guid( p+1, &component );
if( !r )
return ERROR_INVALID_PARAMETER;
TRACE("component %s\n", debugstr_guid( &component ));
if (szProduct)
StringFromGUID2( &product, szProduct, MAX_FEATURE_CHARS+1 );
if (szComponent)
StringFromGUID2( &component, szComponent, MAX_FEATURE_CHARS+1 );
if (szFeature)
{
memcpy( szFeature, &szDescriptor[20], len*sizeof(WCHAR) );
szFeature[len] = 0;
}
len = ( &p[21] - szDescriptor );
TRACE("length = %d\n", len);
*pUsed = len;
return ERROR_SUCCESS;
}
UINT WINAPI MsiDecomposeDescriptorA( LPCSTR szDescriptor, LPSTR szProduct,
LPSTR szFeature, LPSTR szComponent, DWORD *pUsed )
{
WCHAR product[MAX_FEATURE_CHARS+1];
WCHAR feature[MAX_FEATURE_CHARS+1];
WCHAR component[MAX_FEATURE_CHARS+1];
LPWSTR str = NULL, p = NULL, f = NULL, c = NULL;
UINT r;
TRACE("%s %p %p %p %p\n", debugstr_a(szDescriptor), szProduct,
szFeature, szComponent, pUsed);
str = strdupAtoW( szDescriptor );
if( szDescriptor && !str )
return ERROR_OUTOFMEMORY;
if (szProduct)
p = product;
if (szFeature)
f = feature;
if (szComponent)
c = component;
r = MsiDecomposeDescriptorW( str, p, f, c, pUsed );
if (r == ERROR_SUCCESS)
{
WideCharToMultiByte( CP_ACP, 0, p, -1,
szProduct, MAX_FEATURE_CHARS+1, NULL, NULL );
WideCharToMultiByte( CP_ACP, 0, f, -1,
szFeature, MAX_FEATURE_CHARS+1, NULL, NULL );
WideCharToMultiByte( CP_ACP, 0, c, -1,
szComponent, MAX_FEATURE_CHARS+1, NULL, NULL );
}
msi_free( str );
return r;
}
UINT WINAPI MsiEnumProductsA(DWORD index, LPSTR lpguid)
{
DWORD r;
WCHAR szwGuid[GUID_SIZE];
TRACE("%d %p\n", index, lpguid);
if (NULL == lpguid)
return ERROR_INVALID_PARAMETER;
r = MsiEnumProductsW(index, szwGuid);
if( r == ERROR_SUCCESS )
WideCharToMultiByte(CP_ACP, 0, szwGuid, -1, lpguid, GUID_SIZE, NULL, NULL);
return r;
}
UINT WINAPI MsiEnumProductsW(DWORD index, LPWSTR lpguid)
{
HKEY hkeyFeatures = 0;
DWORD r;
WCHAR szKeyName[SQUISH_GUID_SIZE];
TRACE("%d %p\n", index, lpguid);
if (NULL == lpguid)
return ERROR_INVALID_PARAMETER;
r = MSIREG_OpenFeatures(&hkeyFeatures);
if( r != ERROR_SUCCESS )
return ERROR_NO_MORE_ITEMS;
r = RegEnumKeyW(hkeyFeatures, index, szKeyName, SQUISH_GUID_SIZE);
if( r == ERROR_SUCCESS )
unsquash_guid(szKeyName, lpguid);
RegCloseKey(hkeyFeatures);
return r;
}
UINT WINAPI MsiEnumFeaturesA(LPCSTR szProduct, DWORD index,
LPSTR szFeature, LPSTR szParent)
{
DWORD r;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -