讀註冊表的時候要引用到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;