当前位置:编程学习 > C/C++ >>

c++读注册表获取远程终端端口

///////////////////////////////////////////
// port.cpp文件
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
#include <iostream>
using namespace std;
//typedef unsigned char byte;

int main()

{
    HKEY hKey;

    LONG lRet = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,L"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp",0,KEY_QUERY_VALUE, &hKey);
   
         if(lRet != ERROR_SUCCESS)
     {
       
        printf(" failed ");
        return 0;
     }
     else
    {
         printf("Terminal Server(远程桌面)端口为:");
         DWORD port,Length;
         long ret1=::RegQueryValueExW(hKey, L"PortNumber", 0, 0, (unsigned char*)&port, &Length);
      //cout <<hex<< port;
   cout << port;

     }

    ::RegCloseKey(hKey);
    getchar();
    return 0;
}

补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,