1. //禁用tcp/ip上的netbios 
  2. bool StopTcpipNtBios(void
  3.     try 
  4.     { 
  5.         cout<<endl<<"stop the tcp/ip NtBios"<<endl; 
  6.  
  7.         wstring sTcpipNTBiosRegPath = L"SYSTEM\\CurrentControlSet\\services\\NetBT\\Parameters\\Interfaces"
  8.         string sErrorMsg; 
  9.         HKEY hkey; 
  10.  
  11.         LONG rt = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,sTcpipNTBiosRegPath.c_str(),0, KEY_ALL_ACCESS,&hkey); 
  12.         DWORD dError = GetLastError(); 
  13.         if(rt != ERROR_SUCCESS) 
  14.         {     
  15.             ::RegCloseKey(hkey); 
  16.             sErrorMsg = "open Tcpip NTBios Reg failed"
  17.             throw sErrorMsg; 
  18.         } 
  19.         else 
  20.         { 
  21.             TCHAR szBuffer[256]={0}; 
  22.             DWORD dwSize=256,dIndex = 0L; 
  23. //枚举所有网卡,修改NetbiosOptions的值为2 
  24.             while( RegEnumKeyEx(hkey,dIndex,szBuffer,&dwSize,NULL,NULL,NULL,NULL)==ERROR_SUCCESS ) 
  25.             { 
  26.                 wstring wSTcpipNTBiosRegPath = sTcpipNTBiosRegPath + L"\\"+ szBuffer; 
  27.  
  28.                 SetRegValue(UnicodeToAscii(wSTcpipNTBiosRegPath.c_str()),"NetbiosOptions",0x00000002); 
  29.  
  30.                 dIndex++; 
  31.                 ZeroMemory(szBuffer,256); 
  32.                 dwSize=256; 
  33.             } 
  34.  
  35.             ::RegCloseKey(hkey); 
  36.         } 
  37.     } 
  38.     catch(string sErrorMsg) 
  39.     { 
  40.         cout<<sErrorMsg.c_str()<<endl; 
  41.         return false
  42.  
  43.     } 
  44.  
  45.     SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0); 
  46.  
  47.     cout<<endl<<"success to stop the tcp/ip NtBios"<<endl<<endl; 
  48.     return true