谢谢 域
这是别人写的提升权限的代码,但是我发现没什么用
function RegSetPrivilege(AhKey: HKEY; pszSubKey: PChar;
pSD: PSecurityDescriptor; bRecursive: BOOL): BOOL;
var
bRet: BOOL;
hSubKey: HKEY;
lRetCode: LONGINT;
pszKeyName: pchar;
dwSubKeyCnt: DWORD;
dwMaxSubKey: DWORD;
dwValueCnt: DWORD;
dwMaxValueName: DWORD;
dwMaxValueData: DWORD;
i: DWORD;
label cleanup;
begin
bRet := FALSE;
hSubKey := 0;
pszKeyName := nil;
if (pszSubKey = nil) then
goto cleanup;
// open the key for WRITE_DAC access
lRetCode := RegOpenKeyEx(AhKey, pszSubKey, 0, WRITE_DAC, hSubKey);
if (lRetCode <> ERROR_SUCCESS) then
goto cleanup;
// apply the security descriptor to the registry key
lRetCode := RegSetKeySecurity(hSubKey,
DACL_SECURITY_INFORMATION, pSD);
if (lRetCode <> ERROR_SUCCESS) then
begin
// RaiseLastOSError;
goto cleanup;
end;
if (bRecursive) then
begin
// reopen the key for KEY_READ access
RegCloseKey(hSubKey);
hSubKey := 0;
lRetCode := RegOpenKeyEx(AhKey, pszSubKey, 0, KEY_READ, hSubKey);
if (lRetCode <> ERROR_SUCCESS) then
goto cleanup;
// first get an info about this subkey ...
lRetCode := RegQueryInfoKey(hSubKey, 0, 0, 0, @dwSubKeyCnt, @dwMaxSubKey,
0, @dwValueCnt, @dwMaxValueName, @dwMaxValueData, 0, 0);
if (lRetCode <> ERROR_SUCCESS) then
goto cleanup;
// enumerate the subkeys and call RegTreeWalk() recursivly
getmem(pszKeyName, MAX_PATH + 1);
for I := 0 to dwSubKeyCnt - 1 do // Iterate
begin
lRetCode := RegEnumKey(hSubKey, i, pszKeyName, MAX_PATH + 1);
if (lRetCode = ERROR_SUCCESS) then
begin
RegSetPrivilege(hSubKey, pszKeyName, pSD, TRUE);
end
else if (lRetCode = ERROR_NO_MORE_ITEMS) then
begin
break;
end;
end;
freemem(pszKeyName);
end;
bRet := TRUE; // indicate success
cleanup:
if (hSubKey <> 0) then
begin
RegCloseKey(hSubKey);
end;
result := bRet;
end;