溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

c++禁用 tcp/ip 上的netbios

發(fā)布時(shí)間:2020-07-12 07:49:39 來(lái)源:網(wǎng)絡(luò) 閱讀:292 作者:luwenji309 欄目:移動(dòng)開(kāi)發(fā)

 

  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. //枚舉所有網(wǎng)卡,修改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

 

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI