首页 > 程序开发 > 综合编程 > 安全编程 >

从注册表读取服务状态

2009-01-01

function ReadFromRegistry(ServiceName: string; KeyName: string; IsInt: Integer = 0): string;var { 读取注册表中的服务信息 }reg: TRegistry;beginreg := TRegistry.Create;try    reg.RootKey := HKEY_LOCAL_MACHIN

function ReadFromRegistry(ServiceName: string; KeyName: string; IsInt: Integer = 0): string;
var { 读取注册表中的服务信息 }
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey(SYSTEMCurrentControlSetServices + ServiceName, False);
if IsInt <> 0 then
begin
case reg.ReadInteger(KeyName) of
2: Result := 自动;
3: Result := 手动;
4: Result := 已禁用;
end;
end
else
Result := reg.ReadString(KeyName);
finally
reg.CloseKey;
reg.Free;
end;
end;

procedure WriteIntegerToRegistry(ServiceName: string; KeyName: string; KeyValue: Integer);
var { 写入一个服务整型值到注册表 }
reg: TRegistry;
begin
reg := TRegistry.Create;
try
reg.RootKey := HKEY_LOCAL_MACHINE;
reg.OpenKey(SYSTEMCurrentControlSetServices + ServiceName, False);
reg.WriteInteger(KeyName, KeyValue);
finally
reg.CloseKey;
reg.Free;
end;
end;

相关文章
最新文章
热点推荐