/*
Code by tangyue
Mail wellsty@sina.com
*/
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <winreg.h>
#define MY_BUFSIZE 256
void Usage (void);
void ShowVersion(void);
int main (int argc, char *argv[])
{
int n;
HKEY hKEY;
DWORD Number=0;
DWORD MaxSubKeyLen;
DWORD i;
FILETIME ftLastWriteTime;
char data_Set[MY_BUFSIZE];
char data_Set1[MY_BUFSIZE];
DWORD Maxlen = 256;
DWORD dwBufLen = MY_BUFSIZE;
HKEY hKeyAdapter,hKeyNetBios;
CHAR achKey[MY_BUFSIZE];
TCHAR adapterNameGet[256];
DWORD cbData=256;
long lret;
for (n=1;n<argc;n++) {
if (argv[n][0] == '-') {
switch(argv[n][1]) {
case '?':Usage();
break;
case 'v':ShowVersion();
}
}
}
if(lret = ERROR_SUCCESS != RegOpenKeyEx( HKEY_LOCAL_MACHINE,("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards"),0, KEY_READ,&hKEY)){
fprintf(stderr,"error!\n");
exit(1);
}
if(ERROR_SUCCESS!= RegQueryInfoKey( hKEY,NULL,NULL,NULL, &Number,&MaxSubKeyLen, NULL, NULL,NULL,NULL, NULL,NULL)){
RegCloseKey(hKEY);
fprintf(stderr,"error\n");
exit(1);
}
DWORD dwIndex=0,lpcbname=100;
long ret;
for (i = 0; i < Number; i++){
ZeroMemory(achKey,100);
Maxlen = 256;
cbData = 256;
ret = RegEnumKeyEx(hKEY,i,achKey,&Maxlen,NULL,NULL,NULL,&ftLastWriteTime);
sprintf((char *)data_Set,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards\\%s",achKey);
RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set,0, KEY_READ,&hKeyAdapter);
RegQueryValueEx(hKeyAdapter, "ServiceName", NULL,NULL, (LPBYTE)adapterNameGet, &cbData);
ZeroMemory(achKey,100);
Maxlen = 256;
cbData = 256;
sprintf((char *)data_Set1,"SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters\\Interfaces\\Tcpip_%s",adapterNameGet);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_Set1,0, KEY_WRITE,&hKeyNetBios)){
fprintf(stderr,"error\n");
}
DWORD dwData;
dwData = 2;
if (RegSetValueEx(hKeyNetBios, // subkey handle
"NetbiosOptions", // value name
0, // must be zero
REG_DWORD, // value type
(LPBYTE) &dwData, // pointer to value data
sizeof(DWORD))) // length of value data
fprintf(stderr,"Could not set the supported types.\n");
RegCloseKey(hKeyAdapter);
RegCloseKey(hKeyNetBios);
}
RegCloseKey(hKEY);
printf("\nNetBios had Disabled!\n");
return 0;
}
void Usage (void) {
fprintf(stderr,
"Usage: netbios [-?] [-v] \n"
"-?:show help\n"
"-v:show version\n"
);
exit(0);
}
void ShowVersion(void) {
fprintf(stderr,
"Win\tnetbios\tVer1.0.0\t2004.12.16\n"
);
exit(0);
}