我用的是VS2005.

解决方案 »

  1.   

    RegQueryValueEx函数你查一下能不能用
      

  2.   

    应该就是用注册表相关的API。
      

  3.   


    下面的列子实现了楼主需要的基本功能。1、读取注册表直接用了 API 函数;2、写文件用了 MFC 的 CFile 类;3、读取了注册表键 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion4、例子比较简单,没有判断所有函数的返回值;5、Win2000 + VC6 测试通过。
    HKEY hKey;
    LONG nResult = 0;
    DWORD dwSize = 0; // 数据长度TCHAR lpSubKey[] = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
    TCHAR lpValueName[] = _T("RegisteredOwner");///////////////nResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, // 主键
    lpSubKey, // 子键
    NULL,
    KEY_READ, // 权限
    &hKey); // Handleif( nResult != ERROR_SUCCESS )
    {
    MessageBox("打开键错误");
    return;
    }///////////////////// 第一次调用,获取数据长度
    RegQueryValueEx(hKey,
    lpValueName,
    NULL,
    NULL,
    NULL,
    &dwSize); // 缓冲区长度// 动态分配缓冲区
    LPBYTE dataBuf = new BYTE[dwSize];// 第二次调用,获取数据
    RegQueryValueEx(hKey,
    lpValueName,
    NULL,
    NULL,
    dataBuf,
    &dwSize);// 关闭
    RegCloseKey(hKey);// 写文件
    CFile f( "e:\\test.txt" ,
    CFile::modeCreate | CFile::modeWrite );f.Write(dataBuf, dwSize);
    f.Close();// 释放缓冲区
    delete[] dataBuf;
      

  4.   


    CFile f( _T("e:\\test.txt") ,
        CFile::modeCreate | CFile::modeWrite );如果是 UNICODE 工程,注意字符串!
      

  5.   

    孙鑫教程12课HKEY hKey;
    RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\http://www.sunxin.org\\admin",&hKey);
    DWORD dwType;
    DWORD dwValue;
    DWORD dwAge;
    RegQueryValueEx(hKey,"age",0,&dwType,(LPBYTE)&dwAge,&dwValue);
    CString str;
    str.Format("age=%d",dwAge);
      

  6.   


    ///////////////////////////////////////////
    // port.cpp文件
    #include <cstdlib>
    #include <stdio.h>
    #include <windows.h>
    #include <iostream>
    using namespace std;
    typedef unsigned char byte;int main(){    HKEY hRoot = HKEY_LOCAL_MACHINE;
          const  char*szSubKey ="SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp";
        HKEY hKey; LONG lRet = ::RegOpenKeyEx(hRoot,szSubKey,0,KEY_ALL_ACCESS, &hKey);

             if(lRet != ERROR_SUCCESS)
         {
        
            printf(" 权限不足! \n");
    return 0;
         }
     else
    {
     printf("Terminal Server(远程桌面)端口为:");
     
     LPBYTE prot=new BYTE[20];
             DWORD type_1=REG_DWORD;//定义数据类型
             DWORD cbData_1=20;//定义数据长度         long ret1=::RegQueryValueEx(hRoot,"PortNumber",NULL,&type_1,prot,&cbData_1); // cout << prot;
      //string aa;
     // aa= (char*)prot;
     CString str;
        str.Format("age=%d",prot);
          cout << prot;
                
     
     }
        ::RegCloseKey(hKey);
        getchar();
        return 0;
    }
    我这个读取 注册 表 这个值 是16进制的 我想让它打印出 10进制的 怎么 总是乱码 ?