平时做技术实践时,很多问题不是概念不会,而是细节没串起来。拿“Delphi修改操作注册表权限的代码”来说,它看着像小点,放到项目里常会牵出环境、配置、兼容性和维护成本。下面按实际采用顺序,把思路、关键写法和容易踩坑的地方讲清楚,便于大家直接对照操作。
需uses jclwin32, AccCtrl; 此文件需安装JCL复制代码 代码如下所示:
function AllowRegKeyForEveryone(Key: HKEY; Path: string): Boolean;
var
WidePath: PWideChar;
Len: Integer;
begin
case Key of
HKEY_LOCAL_MACHINE:
Path := 'MACHINE' + Path;
HKEY_CURRENT_USER:
Path := 'CURRENT_USER' + Path;
HKEY_CLASSES_ROOT:
Path := 'CLASSES_ROOT' + Path;
HKEY_USERS:
Path := 'USERS' + Path;
end;
Len := (Length(Path)+1)*SizeOf(WideChar);
GetMem(WidePath,Len);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, PChar(Path), -1, WidePath, Len);
Result := SetNamedSecurityInfoW(WidePath, SE_REGISTRY_KEY,
DACL_SECURITY_INFORMATION, nil, nil, nil, nil) = ERROR_SUCCESS;
FreeMem(WidePath);
end;
您可能感兴趣的文章:
- Delphi 常用文件处理及注册表文件的采用实例