我给你一例子,我自己编的.
program TCSBA;uses
  Sysutils,
  Dialogs,
  FileCtrl,
  Forms,
  Registry,
  Windows,
  MainFrm in 'MainFrm.pas' {MainWindows},
  TCSBADM in 'TCSBADM.pas' {TCSBADataModule: TDataModule},
  LoginFrm in 'LoginFrm.pas' {LoginForm},
  AboutFrm in 'AboutFrm.pas' {OKRightDlg},
  ChildFrm in 'ChildFrm.pas' {ChildForm},
  BrowseFrm in 'BrowseFrm.pas' {MessBrowseFrm},
  PrinteCardGM in 'PrinteCardGM.pas',
  LookUpFrm in 'LookUpFrm.pas' {MessLookUpForm},
  GroupPrintFrm in 'GroupPrintFrm.pas' {GroupPrintForm},
  MesInExportFrm in 'MesInExportFrm.pas' {MesInExportForm},
  MessageModiFrm in 'MessageModiFrm.pas' {MessageModifyForm},
  ModifyFrm in 'ModifyFrm.pas' {ModifyForm};{$R *.RES}
var
  registerTemp : TRegistry;
  DriverStr:String;
  TcsKeyValue:String;
  TCSBCAODBC:Boolean;begin  registerTemp := TRegistry.Create; //建立一个Registry实例
  with registerTemp do
  begin
    RootKey:=HKEY_LOCAL_MACHINE; //设置根键值为HKEY_LOCAL_MACHINE    {检测系统是否注册}
    TcsKeyValue:='False';
    if OpenKey('Software\TCSBCASystem',False) then
      if ValueExists('TCSBCA') then
        TcsKeyValue:=ReadString('TCSBCA');
    CloseKey;    {如果系统没有注册}
    if TcsKeyValue='False' then
    begin
      {检测系统是否有SQL Server的ODBC驱动程序}
      if openkey('Software\ODBC\ODBCINST.INI\ODBC Drivers',false) then
      begin
        if not ValueExists('SQL Server') then
        begin
          ShowMessage('系统中没有装入SQL Server的ODBC驱动程序,无法启动程序');
          Closekey;
          halt;
        end;
        CloseKey;
      end
      else
      begin
        ShowMessage('系统注册表问题,无法启动程序');
        CloseKey;
        halt;
      end;      {读取SQL Server的驱动程序的存放位置}
      if Openkey('Software\ODBC\ODBCINST.INI\SQL Server',false) then
        DriverStr:=ReadString('Driver')
      else
      begin
        ShowMessage('读取系统中SQL Server的ODBC驱动程序有误,导致无法加载启动程序');
        Closekey;
        halt;
      end;
      CloseKey;      {检测系统是否创建TCSBCA_ODBC}
      if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',False) then
        if ValueExists('TCSBCA_ODBC1') then
          TCSBCAODBC:=True
        else
          TCSBCAODBC:=False;
      CloseKey;
      {创建TCSBCA_ODBC}      if not TCSBCAODBC then
        if OpenKey('Software\ODBC\ODBC.INI\ODBC Data Sources',True) then
        begin
           WriteString( 'TCSBCA_ODBC', 'SQL Server' );
           CloseKey;
        end
        else
        begin
          ShowMessage('写入系统注册表数据错误,无法加载启动程序');
          Closekey;
          halt;
        end;      if not TCSBCAODBC then
      begin
        if OpenKey('Software\ODBC\ODBC.INI\TCSBCA_ODBC',True) then
        begin
          WriteString( 'Database', 'TCSBCA_DB' );//指定数据库
          WriteString( 'Description', 'TCSBCA系统SQL Server数据源' ); //数据源描述
          //驱动程序DLL文件,根据系统安装的目录不同而不同。
          WriteString( 'Driver', DriverStr ); //驱动程序
          WriteString( 'LastUser', 'sa' );
          WriteString( 'Server', '(local)' );
          TCSBCAODBC:=True ;
          CloseKey;
        end
        else
        begin
          ShowMessage('写入系统注册表数据错误,无法加载启动程序');
          Closekey;
          halt;
        end;
      end;
      {向系统注册表写入系统注册信息}
      if OpenKey('Software\TCSBCASystem',True) then
      begin
        WriteString('TCSBCA','True');
        CloseKey;
      end
      else
      begin
        ShowMessage('写入系统注册表数据错误,无法加载启动程序');
        Closekey;
        halt;
      end;    end;  end;  if not DirectoryExists('Photo') then
  begin
    if not CreateDir('Photo') then
    begin
      ShowMessage('因无法创建 Photo 目录导致无法启动程序');
      halt;
    end;
  end;  if not DirectoryExists('StudentPhoto') then
  begin
    if not CreateDir('StudentPhoto') then
    begin
      ShowMessage('因无法创建 StudentPhoto 目录导致无法启动程序');
      halt;
    end;
  end;  if Not FileExists(ExtractFilePath(Application.ExeName)+'LocalMess.Px') then
  begin
    ShowMessage('重要数据文件丢失,无法启动程序');
    halt;
  end;  Application.Initialize;
  Application.Title := '北京建筑工程学院考试证管理系统';
  Application.CreateForm(TMainWindows, MainWindows);
  Application.Run;end.