首页 > 学院 > 操作系统 > 正文

从注册表读取服务状态

2024-06-28 13:06:40
字体:
来源:转载
供稿:网友

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('SYSTEM/CurrentControlSet/Services/' + 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('SYSTEM/CurrentControlSet/Services/' + ServiceName, False);
    reg.WriteInteger(KeyName, KeyValue);
finally
    reg.CloseKey;
    reg.Free;
end;
end;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表