PowerUsers 权限下 读注册表不行,写可以 困惑!!!

wanghongit 2007-10-29 11:30:13
UINT CRegistry::GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault)
{
ASSERT(lpszSection != NULL);
ASSERT(lpszEntry != NULL);

HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return nDefault;
DWORD dwValue;
DWORD dwType;
DWORD dwCount = sizeof(DWORD);
LONG lResult = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, &dwType,
(LPBYTE)&dwValue, &dwCount);
RegCloseKey(hSecKey);
if (lResult == ERROR_SUCCESS)
{
ASSERT(dwType == REG_DWORD);
ASSERT(dwCount == sizeof(dwValue));
return (UINT)dwValue;
}
return nDefault;
}

CRegistry reg;
sTemp = _T("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\") + sDevice + _T("\\Connection\\");
lpszSubKey = (LPCTSTR)sTemp.GetBuffer(20000);
sTemp.ReleaseBuffer();
nValue = reg.GetProfileInt(lpszSubKey, _T("MediaSubType"), 0);


注册表的位置是SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1 -08002BE10318}\{5C55B069-AA1D-4EC6-9921-2B670E4486DA}\Connection\
administrator 权限可以读到,但是powerusers就不行
但是可以有修改权限
BOOL CRegistry::WriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes)
{
ASSERT(lpszSection != NULL);

LONG lResult;
HKEY hSecKey = GetSectionKey(lpszSection);
if (hSecKey == NULL)
return FALSE;
lResult = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY,
pData, nBytes);
RegCloseKey(hSecKey);
return lResult == ERROR_SUCCESS;
}
注册表的位置是 SOFTWARE\Microsoft\EAPOL\Parameters\Interfaces\{5C55B069-AA1D-4EC6-9921-2B670E4486DA}
reg.WriteProfileBinary(lpszSubKey, _T("1"), (LPBYTE)cInfVal, nDataSize)

这个可以修改,不知道为什么
...全文
125 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghongit 2007-10-29
  • 打赏
  • 举报
回复
能写不能读,太诡异了,高手帮我看看
wanghongit 2007-10-29
  • 打赏
  • 举报
回复
HKEY CRegistry::GetSectionKey(LPCTSTR lpszSection, BOOL bCreate)
{
ASSERT(lpszSection != NULL);
HKEY hSectionKey = NULL;

if (m_strRootKey.CompareNoCase(_T("HKEY_CLASSES_ROOT")) == 0)
{
m_hKey = HKEY_CLASSES_ROOT;
}
else if (m_strRootKey.CompareNoCase(_T("HKEY_CURRENT_USER")) == 0)
{
m_hKey = HKEY_CURRENT_USER;
}
else if (m_strRootKey.CompareNoCase(_T("HKEY_LOCAL_MACHINE")) == 0)
{
m_hKey = HKEY_LOCAL_MACHINE;
}
else if (m_strRootKey.CompareNoCase(_T("HKEY_USERS")) == 0)
{
m_hKey = HKEY_USERS;
}
else if (m_strRootKey.CompareNoCase(_T("HKEY_CURRENT_CONFIG")) == 0)
{
m_hKey = HKEY_CURRENT_CONFIG;
}
else
{
m_hKey = HKEY_LOCAL_MACHINE;
}

if (!RegOpenKeyEx(m_hKey, lpszSection, 0, KEY_WRITE|KEY_READ, &hSectionKey) == ERROR_SUCCESS)
{
m_strLogInfo.Format(_T("%s"), lpszSection);

CCommandModule::WriteLineStringToLog(m_strLogInfo);
return NULL;
}

m_strLogInfo.Format(_T("%s"), lpszSection);

CCommandModule::WriteLineStringToLog(m_strLogInfo);
return hSectionKey;
}
star119119 2007-10-29
  • 打赏
  • 举报
回复
LONG RegOpenKey(
HKEY hKey,
LPCTSTR lpSubKey,
PHKEY phkResult
);
i_love_pc 2007-10-29
  • 打赏
  • 举报
回复
能写不能读??
ouyh12345 2007-10-29
  • 打赏
  • 举报
回复
GetSectionKey是怎样写的,里面都有什么权限?
wanghongit 2007-10-29
  • 打赏
  • 举报
回复
结帖,RegOpenKeyEx 时用 KEY_QUERY_VALUE 打开就行了
但是我不明白为什么这个键值HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\{5C55B069-AA1D-4EC6-9921-2B670E4486DA}\Connection\
用写权限打不开,别的却可以。
wanghongit 2007-10-29
  • 打赏
  • 举报
回复
加上这个
HRESULT CMyDlg::SetPrivilege(LPCTSTR privilege, BOOL bEnable)
{
TOKEN_PRIVILEGES tpPrevious;
TOKEN_PRIVILEGES tp;
DWORD cbPrevious = sizeof(TOKEN_PRIVILEGES);
LUID luid;
HANDLE hTokenUsed;

if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hTokenUsed))
goto _Error;

if (!LookupPrivilegeValue(NULL, privilege, &luid ))
goto _Error;

tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = 0;

if (!AdjustTokenPrivileges(hTokenUsed, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), &tpPrevious, &cbPrevious))
goto _Error_CloseHandle;

tpPrevious.PrivilegeCount = 1;
tpPrevious.Privileges[0].Luid = luid;

if (bEnable)
tpPrevious.Privileges[0].Attributes |= SE_PRIVILEGE_ENABLED;
else
tpPrevious.Privileges[0].Attributes &= ~SE_PRIVILEGE_ENABLED;

if (!AdjustTokenPrivileges(hTokenUsed, FALSE, &tpPrevious, cbPrevious, NULL, NULL))
goto _Error_CloseHandle;

CloseHandle(hTokenUsed);

return S_OK;

HRESULT hr;

_Error:
hr = GetLastError();
return hr;

_Error_CloseHandle:
hr = GetLastError();
CloseHandle(hTokenUsed);
return hr;
}
在RegOpenKeyEx(m_hKey, lpszSection, 0, KEY_WRITE|KEY_READ, &hSectionKey) == ERROR_SUCCESS之前调用
SetPrivilege(SE_BACKUP_NAME,TRUE);
SetPrivilege(SE_RESTORE_NAME,TRUE);
还是不好用,不知道什么原因
Pipi0714 2007-10-29
  • 打赏
  • 举报
回复
查看你的用户的注册表权限,加上能度即可
凤矶 2007-10-29
  • 打赏
  • 举报
回复
LookupPrivilegeValue
wanghongit 2007-10-29
  • 打赏
  • 举报
回复
怎么取?
凤矶 2007-10-29
  • 打赏
  • 举报
回复
SE_BACKUP_NAME
SE_RESTORE_NAME

LZ这两个权限取得没有

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧