设为首页 加入收藏

TOP

VC++ 修改计算机名称 SetComputerName
2014-11-23 19:15:37 】 浏览:5072
Tags:修改 计算机 名称 SetComputerName
函数原型:
//By MoreWindows-(http://blog.csdn.net/MoreWindows)
BOOLWINAPISetComputerName(
__in LPCTSTRlpComputerName
);
对于计算机名称有一定的要求,MSDN的解释如下:
The computer name that will take effect the next time the computer is started. The name must not be longer than MAX_COMPUTERNAME_LENGTH characters.
The standard character set includes letters, numbers, and the following symbols: ! @ # $ % ^ & ' ) ( . - _ { } ~ . If this parameter contains one or more characters that are outside the standard character set, SetComputerName returns ERROR_INVALID_PARAMETER.
[cpp]
// VC++修改计算机名称
// http://blog.csdn.net/more windows/article/details/8659430
//By MoreWindows-(http://blog.csdn.net/MoreWindows)
#include
#include
#include
int main()
{
printf(" VC++修改计算机名称 \n");
printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");
const int MAX_BUFFER_LEN = 500;
char szBuffer[MAX_BUFFER_LEN];
DWORD dwNameLen;
dwNameLen = MAX_BUFFER_LEN;
if (!GetComputerName(szBuffer, &dwNameLen))
{
printf("Error %d\n", GetLastError());
return -1;
}
printf("当前计算机名为: %s\n", szBuffer);
printf("要改名吗?(y/n)\n");
int ch = getch();
ch = toupper(ch);
if (ch == 'Y')
{
printf("请输入新名称:");
gets(szBuffer);
if (strlen(szBuffer) != 0)
{
if (SetComputerName(szBuffer))
printf("恭喜!改名成功,重启后生效\n");
else
printf("Error %d\n", GetLastError());
}
}
return 0;
}
// VC++修改计算机名称
// http://blog.csdn.net/morewindows/article/details/8659430
//By MoreWindows-(http://blog.csdn.net/MoreWindows)
#include
#include
#include
int main()
{
printf(" VC++修改计算机名称 \n");
printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");
const int MAX_BUFFER_LEN = 500;
char szBuffer[MAX_BUFFER_LEN];
DWORD dwNameLen;
dwNameLen = MAX_BUFFER_LEN;
if (!GetComputerName(szBuffer, &dwNameLen))
{
printf("Error %d\n", GetLastError());
return -1;
}
printf("当前计算机名为: %s\n", szBuffer);
printf("要改名吗?(y/n)\n");
int ch = getch();
ch = toupper(ch);
if (ch == 'Y')
{
printf("请输入新名称:");
gets(szBuffer);
if (strlen(szBuffer) != 0)
{
if (SetComputerName(szBuffer))
printf("恭喜!改名成功,重启后生效\n");
else
printf("Error %d\n", GetLastError());
}
}
return 0;
}先修改下
\
重启后可以发现计算机的名称已经被修改了。
\
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇mfc vc vs 一个控件贴到另一个控.. 下一篇VC++获取屏幕大小第一篇 像素大小..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目