修改UDL文件


uses  OleDB, ActiveX, ComObj;







var

  DataInit: IDataInitialize;                  //定义接口

  SouPath, SouStr, DesStr: POleStr;

  tmp, s1, s2: string;

begin

  tmp := 'C:\Program Files\Common Files\System\Ole DB\Data Links\ShichADOConfig.UDL';

  SouPath := StringToOleStr(tmp);

  DataInit := CreateComObject(CLSID_DATALINKS) as IDataInitialize;        //创建接口

  DataInit.LoadStringFromStorage(SouPath, SouStr);

  s1 := WideCharToString(SouStr);

  s2 := Copy(SouStr, 0, Pos('Initial Catalog=',s1) - 1);

  s1 := Copy(SouStr, Pos('Initial Catalog=', s1) , Length(SouStr) - Pos('Initial Catalog=',s1) +1 );

  s1 := Copy(s1, Pos(';', s1), Length(s1)- Pos(';', s1) +1 );

  s2 := s2 + 'Initial Catalog=好记' + s1;

  DesStr := StringToOleStr(s2);

  if DeleteFile(tmp) then

    DataInit.WriteStringToStorage(SouPath, DesStr, 1);

  DataInit := nil;                        //释放

end;

 

你可能感兴趣的:(文件)