카테고리 없음

리모트 데스크탑 포트 번호 바꿔주는 프로그램 소스

목사 2009. 3. 26. 20:31

 
DWORD GetRDPPortNo()
{
 HKEY hKey;
 long dwSize=0;
 DWORD PortNo=3389;
 DWORD dwDisp, dwType;

 if (RegCreateKeyEx(
  HKEY_LOCAL_MACHINE,       
  "System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp",
  0,
  NULL,
  REG_OPTION_NON_VOLATILE,
  KEY_READ,
  NULL,
  &hKey,
  &dwDisp) == ERROR_SUCCESS)
 {
  dwSize=sizeof(DWORD);
  RegQueryValueEx( hKey, "PortNumber", NULL, &dwType, (unsigned char *)&PortNo, (unsigned long *)&dwSize);
 
  if (!dwSize) PortNo=3389;

  RegCloseKey(hKey);
 }

 return PortNo;
}

void SetRDPPortNo(DWORD PortNo)
{
 HKEY hKey;
 DWORD dwDisp;

 if (RegCreateKeyEx(
  HKEY_LOCAL_MACHINE,       
  "System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp",
  0,
  NULL,
  REG_OPTION_NON_VOLATILE,
  KEY_ALL_ACCESS,
  NULL,
  &hKey,
  &dwDisp) == ERROR_SUCCESS)
 {
  RegSetValueEx( hKey,
   "PortNumber",
   0,
   REG_DWORD,
   (const unsigned char *)&PortNo,
   sizeof(DWORD));
 
 
  RegCloseKey(hKey);
 }

 if (RegCreateKeyEx(
  HKEY_LOCAL_MACHINE,       
  "System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\connection",
  0,
  NULL,
  REG_OPTION_NON_VOLATILE,
  KEY_ALL_ACCESS,
  NULL,
  &hKey,
  &dwDisp) == ERROR_SUCCESS)
 {
  RegSetValueEx( hKey,
   "PortNumber",
   0,
   REG_DWORD,
   (const unsigned char *)&PortNo,
   sizeof(DWORD));
 
 
  RegCloseKey(hKey);
 }
}
 


출처: http://kurapa.com