吴健雄简介:regedt32修改注册表权限代码为何编译出错`?

来源:百度文库 编辑:中科新闻网 时间:2024/05/09 07:35:10
#include <Windows.h>
#include <Aclapi.h>
#pragma comment (lib,"Advapi32.lib")

void main()
{
DWORD dwRet;
LPSTR SamName = "MACHINE\\SAM\\SAM";
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pOldDacl = NULL;
PACL pNewDacl = NULL;
EXPLICIT_ACCESS ea;
HKEY hKey = NULL;

// 获取SAM主键的DACL
dwRet = GetNamedSecurityInfo(SamName, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION,
NULL, NULL, &pOldDacl, NULL, &pSD);
if (dwRet != ERROR_SUCCESS)
{
printf("GetNamedSecurityInfo Error: %d\n", dwRet);
goto FreeAndExit;
}

// 创建一个ACE,允许Everyone完全控制对象,并允许子对象继承此权限
ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
BuildExplicitAccessWithName(&ea, "Everyone", KEY_ALL_ACCESS, SET_ACCESS,
SUB_CONTAINERS_AND_OBJECTS_INHERIT);

// 将新的ACE加入DACL
dwRet = SetEntriesInAcl(1, &ea, pOldDacl, &pNewDacl);
if (dwRet != ERROR_SUCCESS)
{
printf("SetEntriesInAcl Error: %d\n", dwRet);
goto FreeAndExit;
}

// 更新SAM主键的DACL
dwRet = SetNamedSecurityInfo(SamName, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION,
NULL, NULL, pNewDacl, NULL);
if (dwRet != ERROR_SUCCESS)
{
printf("SetNamedSecurityInfo Error: %d\n", dwRet);
goto FreeAndExit;
}

// 打开SAM的子键
dwRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SAM\\SAM\\Domains\\Account\\Users\\000001F4",
0, KEY_ALL_ACCESS, &hKey);
if (dwRet != ERROR_SUCCESS)
{
printf("RegOpenKeyEx Error: %d\n", dwRet);
goto FreeAndExit;
}

printf("Open SAM Subkey Successfully.\n");

FreeAndExit:
if (hKey) RegCloseKey(hKey);
if (pNewDacl) LocalFree(pNewDacl);
// 还原SAM主键的DACL
if (pOldDacl) SetNamedSecurityInfo(SamName, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION,
NULL, NULL, pOldDacl, NULL);
if (pSD) LocalFree(pSD);
return;
}

为什么无法编译,谁帮忙改下,我急需要个能更改注册表SAM权限的程序。。
各位谁能为小弟实现这个。。

只需要能开通注册表SAM权限的小程序就好了,不需要增加用户名。。谢谢

楼上的要拿分也打几个字啊