联系客服:400-805-1963

c++禁用 tcp/ip 上的netbios
更新:HHH   时间:2023-1-7


 

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

 

返回移动开发教程...