使用iphlpapi读取相关信息,再用netsh命令行设置。 更改DNS: AnsiString strParam = "netsh interface ip set dns name = \"本地连接\" source = static addr = 192.168.0.1" ShellExecute(Handle,"open","netsh",strParam.c_str(),NULL,SW_HIDE);
那你直接就用char*好了,下面这样就行,kingzai的strParam里面不小心多了一个netsh:)char* strParam = "interface ip set dns name = \"本地连接\" source = static addr = 192.168.0.1";ShellExecute(NULL,"open","netsh",strParam,NULL,SW_HIDE);其实在开始运行里面输入 netsh interface ip set dns name = \"本地连接\" source = static addr = 192.168.0.1也是相同的效果^_^
直接用CString str = "netsh interface ip set dns name = \"本地连接\" source = static addr = 192.168.0.1" WinExec(str,SW_HIDE)
//动态创建数据源
写注册表动态创建SQL Server ODBC数据源各个参数的意义:
DBServer: 数据库所在主机
DBName: 数据库名称
DSN: 数据源名称
UID: 登陆用户
返回值:
-1: 没有安装SQL Server驱动程序
-2: 其他错误
0: 成功实现函数:
int MakeSQLServerODBCDSN(LPCTSTR DBServer,LPCTSTR DBName,LPCTSTR DSN,LPCTSTR UID)
{
BOOL bInstallDriver=TRUE;
CRegKey regKey; LONG lRet=regKey.Open(HKEY_LOCAL_MACHINE,"Software\\ODBC\\ODBCINST.INI\\SQL Server");
if(lRet!=ERROR_SUCCESS)
{
bInstallDriver=FALSE;
}
else
{
char szDirverPath[MAX_PATH]="";
DWORD dwCount=100;
lRet=regKey.QueryValue(szDirverPath,"Driver",&dwCount);
if((lRet!=ERROR_SUCCESS)||(dwCount<1))
{
DWORD dwErr=GetLastError();
bInstallDriver=FALSE;
}
regKey.Close();
}
if(!bInstallDriver)
{
return -1;
}
CString strKeyValueName="Software\\ODBC\\ODBC.INI\\";
strKeyValueName+=DSN;
lRet=regKey.Create(HKEY_LOCAL_MACHINE,strKeyValueName);
if(lRet!=ERROR_SUCCESS)
{
return -2;
}
regKey.SetValue(DBName,"Database");
regKey.SetValue("SQLSrv32.dll","Driver");
regKey.SetValue(DBServer,"Server");
regKey.SetValue(UID,"LastUser");
regKey.m_hKey=HKEY_LOCAL_MACHINE;
regKey.SetKeyValue("Software\\ODBC\\ODBC.INI\\ODBC Data Sources","SQL Server",DSN);
regKey.Close();
return 0;
}
更改DNS:
AnsiString strParam = "netsh interface ip set dns name = \"本地连接\" source = static addr = 192.168.0.1"
ShellExecute(Handle,"open","netsh",strParam.c_str(),NULL,SW_HIDE);
你的做法,在编译时提示AnsiString没定义,而且我也不知道iphlpapi是什么东西呀,还请赐教。另外 PiggyXP(【小猪】●至爱VC,至爱网络版●) 的做法,
虽然可以修改,但是用注册表改了dns后,计算机依然可以上网,因为我的目的是,通过更改dns使机器断网,但既然改成无效的dns,机器依然可以上网,好像只有重启计算机才有效,怎么办?
网卡不一样那个键名也不一样吧,而且要是有一个无线的一个有线的俩网卡怎么办呢?
http://www.vckbase.net/document/viewdoc/?id=851
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\ 根据下面的1,2。等等里面的Description来找到你想要修改的网卡的信息位置,然后取得对应的ServiceName 2) 通过刚才得到的"ServiceName"打开相应的键SYSTEM\CurrentControlSet\Services\"ServiceName"\Parameters\TcpIp 修改下面的NameServer ,然后重置一下网卡就OK了
http://search.csdn.net/Expert/topic/2214/2214040.xml?temp=.7825586
netsh interface ip set dns name = \"本地连接\" source = static addr = 192.168.0.1也是相同的效果^_^
WinExec(str,SW_HIDE)