怎麼讀註冊表的值

 

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

發佈了27 篇原創文章 · 獲贊 4 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章