📄 setip.cpp
字号:
// SetIP.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "SetIP.h"
#include <windows.h>
#include <commctrl.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString scmd;
CString sIpaddress;
CString sNetmask;
DWORD dw;
LONG rv;
HKEY key;
if(argc <3)
{
_tprintf(_T("Usage:SetIP Interface IPAddress Subnetmask\n"));
return 0;
}
if(argc ==3)
sNetmask=TEXT("255.255.0.0");
else
sNetmask=argv[3];
sIpaddress=argv[2];
_tprintf(_T("Set IP address for %s with %s Subnetmask %s\n"),argv[1],sIpaddress,sNetmask);
rv=RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("Comm\\DM9CE1\\Parms\\TcpIp"), 0,0,0,
KEY_ALL_ACCESS, NULL, &key, NULL);
if(rv!=ERROR_SUCCESS)
_tprintf(_T("RegCreateKeyEx %d\n"),GetLastError());
dw=0;
rv=RegSetValueEx(key, TEXT("EnableDHCP"), 0, REG_DWORD, (BYTE *)&dw, sizeof(dw));
if(rv!=ERROR_SUCCESS)
_tprintf(_T("RegSetValueEx EnableDHCP %d\n"),GetLastError());
rv=RegSetValueEx(key, TEXT("IpAddress"), 0, REG_SZ, (BYTE *)sIpaddress.AllocSysString(), sIpaddress.GetLength()*2);
if(rv!=ERROR_SUCCESS)
_tprintf(_T("RegSetValueEx IpAddress %d\n"),GetLastError());
rv=RegSetValueEx(key, TEXT("Subnetmask"), 0, REG_SZ, (BYTE *)sNetmask.AllocSysString(), sNetmask.GetLength()*2);
if(rv!=ERROR_SUCCESS)
_tprintf(_T("RegSetValueEx Subnetmask %d\n"),GetLastError());
RegCloseKey(key);
scmd.Format(TEXT("adapter rebind %s"),argv[1]);
CreateProcess(TEXT("\\Windows\\ndisconfig.exe"),scmd, NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL);
_tprintf(_T("\\Windows\\ndisconfig.exe %s,%d\n"),scmd ,GetLastError());
}
return nRetCode;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -