Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RegLoadKey returns 1314 when dll function called from msiexec 1.10.1029.0 and 2.00.2600.0

330 views
Skip to first unread message

Art Komninos

unread,
Dec 3, 2002, 7:21:43 PM12/3/02
to
Calling RegLoadKey in the following returns 1314 when dll function called
from msiexec, using InstallShield custom action. Calling function from test
program, which uses LoadLibrary, succeeds. I use the Privilege function from
Q168877.

CHKEY_USER::CHKEY_USER(const cstring &strProfileKey,
const cstring &strProfilePath):m_hKey(NULL), m_bUnload(false),
m_strProfileKey(strProfileKey)
{
// test privilege for loading hive
if (!_privilege(SE_RESTORE_NAME, true))
return;

// make path to reg file
cstring strRegPath(strProfilePath);
cstring::iterator it(strRegPath.end());

if (_T('\\') != *--it)
{
strRegPath.append(1, _T('\\'));
}

strRegPath.append(_T("ntuser.dat"));

// load key
long lr = RegLoadKey(HKEY_USERS, m_strProfileKey.c_str(),
strRegPath.c_str());
m_bUnload = ERROR_SUCCESS == lr;

if (!m_bUnload)
{
_privilege(SE_RESTORE_NAME, false);
}

if (ERROR_SUCCESS == lr) // open loaded key
{
RegOpenKeyEx(HKEY_USERS, m_strProfileKey.c_str(), 0, KEY_READ, &m_hKey);
}
else if (ERROR_SHARING_VIOLATION == lr) // open current user
{
RegOpenKeyEx(HKEY_CURRENT_USER, NULL, 0, KEY_READ, &m_hKey);
}
}

// from Q168877
bool CHKEY_USER::_privilege(LPTSTR szPrivilege, bool bEnable)
{
HANDLE hToken;
TOKEN_PRIVILEGES tp;

// obtain the processes token
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return false;

// get the luid
if (!LookupPrivilegeValue(NULL, szPrivilege,
&tp.Privileges[0].Luid))
return false;

tp.PrivilegeCount = 1;

if (bEnable)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;

// enable or disable the privilege
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0,
(PTOKEN_PRIVILEGES)NULL, 0))
return false;

if (!CloseHandle(hToken))
return false;

return true;
}


Andreas Magnusson

unread,
Dec 4, 2002, 3:15:53 AM12/4/02
to
Yep, noticed the same thing myself. This probably means that the msiexec.exe
doesn't have the privs.
See also this thread (watch for line-breaks):
http://groups.google.com/groups?hl=en&lr=lang_en|lang_sv&ie=UTF-8&newwindow=
1&threadm=icZh9.7%24kM4.151648%40news.cpqcorp.net&rnum=1&prev=/groups%3Fhl%3
Den%26lr%3Dlang_en%257Clang_sv%26ie%3DISO-8859-1%26newwindow%3D1%26q%3DPRIVI
LEGE%26meta%3Dgroup%253Dmicrosoft.public.platformsdk.msi

/Andreas

"Art Komninos" <IUnk...@vtbl.com> wrote in message
news:u13VdsymCHA.2464@TK2MSFTNGP11...

0 new messages