读注册表的时候要引用到Registry这个单元 下面的代码是实现把指定数据库按当天日期备份到SQL安装目录下的备份目录下
var
vRegPath: TRegistry;
vPath: string;
vCommand: TADOCommand;
begin
vCommand := TADOCommand.Create(nil);
vRegPath := TRegistry.Create;
try
vRegPath.RootKey := HKEY_LOCAL_MACHINE;
vRegPath.OpenKey('Software\Microsoft\MSSQLServer\MSSQLServer', False);
vPath := vRegPath.ReadString('BackupDirectory');
vPath := vPath + '\' + DateToStr(Now) + '.BAK';
vCommand.ConnectionString := DBService.GetConnectionString;
vCommand.CommandTimeout := 10000;
vCommand.CommandText := Format(vSQL, ['Test', vRegPath]);
vCommand.Execute;
finally
vRegPath.Free;
vCommand.Free;
end;