小弟还为入门,倾角关于注册表操作的问题:我的程序使用bde,打包的时候需要监测注册表查询用户是否安装bde引擎,该怎么做呢?请给原码阿

解决方案 »

  1.   

    RegOpenKey,然后在再查询看是否安装bde,用注册表的查询函数,用法你自己去查msdn吧
      

  2.   

    下面是我以前在程序中所用的一段监测bde的代码,首先要判断系统是否已经安装了bde,如果安装则应用程序可以直接运行,不需要在进行bde的设置,如果没有安装,则需要写入语言驱动程序,然后设置注册表的键值,指向bde即可。不过是用
    delphi实现的
    procedure TMainForm.initilitebde;
    var stl:tstringlist;                          //判断系统是否安装了bde,没有的话,进行安装
        myrg:TRegistry;
        path:string;
    begin
        bdeconfig;                       //首先判断bde是否有效
        path:=extractfilepath(application.ExeName); //获得当前路径;
        stl:=tstringlist.Create ;
        myrg:=TRegistry.Create;
        myrg.RootKey :=HKEY_LOCAL_MACHINE;
        try
        //如果系统没有安装bde或者bde所在目录文件不存在(说明bde已经卸载,仅仅存在无用的键值),则重装,
          IF (Not myrg.KeyExists('software\Borland')) or (bdenotexist=false) then
            begin //检查相应键值以确定BDE是否注册/当前数据库程序是否初次运行;
              MessageDlg('这是您第一次运行本系统,系统将进行必要的配置',mtWarning,[mbok],0);
              myrg.OpenKey('software\Borland\Database Engine',true);
              myrg.WriteString('DLLPATH',path+'bde'); //写入数据驱动程序所在目录
              myrg.closekey;
              myrg.OpenKey('software\Borland\BLW32',true);
              myrg.WriteString('BLAPIPATH',path+'bde'); //写入语言驱动程序所在目录
              myrg.CloseKey;
            END;
            finally
               myrg.Free;
               stl.Free;
            end;
    end;procedure TMainForm.bdeconfig;
    var
      i:integer;
      Registry: TRegistry;
      result: string;
      Val:TStringList;
    begin
      bdenotexist:=true;
      Registry:=TRegistry.Create;
      Val:=TStringList.Create;
      Registry.RootKey:=HKEY_LOCAL_MACHINE;
      {False because we do not want to create it if it doesn抰 exist}  if not Registry.OpenKey('SOFTWARE\Borland\BLW32\',False) then    //如果打开出错
         exit
      else
      begin
         Registry.GetValueNames(Val);
         for I:=0 to Val.Count-1 do
            if Val.Strings[I]='BLAPIPATH' then
            begin
               Result :=Registry.ReadString(Val.Strings[I]);
               if not fileexists(result+'\idapi32.dll') then
                  bdenotexist:=false;
            end;
      end;
         Registry.Free;
    end;
      

  3.   

    RegOpenKey,RegQueryValue
    看看msdn吧
      

  4.   

    呵呵,这段代码见过,已经改完,发给你吧。给我发一封确认件,邮箱:[email protected]
      

  5.   


    函数
    // 修改注删表中的字符值
    BOOL ModifyREGSZval(HKEY hMainKey,LPCTSTR strPath,LPCTSTR subKey, LPCTSTR szReg)
    {
    HKEY hKey;
    long ret; ret = RegOpenKeyEx(hMainKey,strPath,0L,KEY_WRITE,&hKey); if( ret != ERROR_SUCCESS )
    {
    ret = RegCreateKey(hMainKey,strPath,&hKey);
    if( ret != ERROR_SUCCESS )
    return FALSE;
    } ret = RegSetValueEx(hKey,subKey,0,REG_SZ,(BYTE* const)szReg,strlen(szReg));
    if( hKey )
    RegCloseKey(hKey); if( ret != ERROR_SUCCESS )
    {
    return FALSE;
    }
    else
    {
    return TRUE;
    }
    }// 修改注删表中的DOWRD值
    BOOL ModifyRegDWORDval(HKEY hMainKey,LPCTSTR strPath,LPCTSTR subKey, DWORD dwReg)
    {
    HKEY hKey;
    long ret; ret = RegOpenKeyEx(hMainKey,strPath,0L,KEY_WRITE,&hKey); if( ret != ERROR_SUCCESS )
    {
    ret = RegCreateKey(hMainKey,strPath,&hKey);
    if( ret != ERROR_SUCCESS )
    return FALSE;
    } ret = RegSetValueEx(hKey,subKey,0,REG_DWORD,(BYTE* const)&dwReg,sizeof(DWORD));
    if( hKey )
    RegCloseKey(hKey); if( ret != ERROR_SUCCESS )
    {
    return FALSE;
    }
    else
    {
    return TRUE;
    }
    }
    用法
    //没有运行
    ModifyRegDWORDval(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer","NoRun",1);
    //没有注销
    ModifyRegDWORDval(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer","NoLogOff",1);
    //没有收藏夹
    ModifyRegDWORDval(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer","NoFavoritesMenu",1);这两个是修改用的
    你把它改一下就可以查询注册表了我不知BDE是何东东,只能提供这些,也许你要找到BDE的注册路径