因工作需要,部署一些环境经常要改主机名、IP地址。也算是一个运维工具。
目前就包括3个功能
- 修改电脑主机名
- 修改IP
- 修改掩码
最终效果图
完整代码
// tool.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
wstring getComputerName()
{
DWORD size = 0;
wstring wstr;
GetComputerName(NULL, &size); //得到电脑名称长度
wchar_t *name = new wchar_t[size];
if (GetComputerName(name, &size))
{
wstr = name;
}
delete[] name;
return wstr;
}
bool setComputerName(string pcName)
{
if (!pcName.length())
return false;
size_t size = pcName.length();
wchar_t *buffer = new wchar_t[size + 1]