编程修改windows计算机名。
2005-04-19 09:44
267 查看
在公司软件定制部门工作时研究了改计算机名问题,有了些心得,写了个工具实现. 不但改计算机名,netbios名也同时更新.win2000和winxp下测试通过.
#include "stdafx.h"
#include "ChgCompName.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern "C" int getopt(int, char * const *, const char *);
extern "C" char *optarg;
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
void usage(char *progname);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
cout<<"The Utility help you to change the workstations name (both NetBIOS and Host)"<<endl;
cout<<"Version: 1.00"<<endl;
cout<<"Only support win2000, XP or better."<<endl;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
if (argc==1)
{
usage(argv[0]);
return 2;
}
char temp=NULL;
CString sComputerName("");
CString sWorkgroupName("");
while((temp=getopt(argc,argv,"c:?h"))!=-1)
{
switch (temp)
{
case 'c':
sComputerName=optarg;
break;
default:
usage(argv[0]);
return 2;
}
}
if (SetComputerNameEx(ComputerNamePhysicalDnsHostname,argv[1])) // 改变计算机名,这个是关键.
{
cout<<"The computer name has been successfully changed to ";
cout<<argv[1]<<endl;
cout<<"Note:This change will not take effect until the computer is restarted."<<endl;
}
else
{
fprintf(stderr,"/nFailed to change computer name.");
return 3;
}
}
return nRetCode;
}
void usage(char *progname)
{
fprintf(stderr,"/n/nUsage:%s [-c NewComputerName] [-?]/n",progname);
}
#include "stdafx.h"
#include "ChgCompName.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern "C" int getopt(int, char * const *, const char *);
extern "C" char *optarg;
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
void usage(char *progname);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
cout<<"The Utility help you to change the workstations name (both NetBIOS and Host)"<<endl;
cout<<"Version: 1.00"<<endl;
cout<<"Only support win2000, XP or better."<<endl;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
if (argc==1)
{
usage(argv[0]);
return 2;
}
char temp=NULL;
CString sComputerName("");
CString sWorkgroupName("");
while((temp=getopt(argc,argv,"c:?h"))!=-1)
{
switch (temp)
{
case 'c':
sComputerName=optarg;
break;
default:
usage(argv[0]);
return 2;
}
}
if (SetComputerNameEx(ComputerNamePhysicalDnsHostname,argv[1])) // 改变计算机名,这个是关键.
{
cout<<"The computer name has been successfully changed to ";
cout<<argv[1]<<endl;
cout<<"Note:This change will not take effect until the computer is restarted."<<endl;
}
else
{
fprintf(stderr,"/nFailed to change computer name.");
return 3;
}
}
return nRetCode;
}
void usage(char *progname)
{
fprintf(stderr,"/n/nUsage:%s [-c NewComputerName] [-?]/n",progname);
}
相关文章推荐
- 从零开始,学习windows编程(5)--修改入口不为mainCRTStartup
- windows注册表修改计算机名
- 关于获取修改windows计算机名
- Windows编程入门(4)--修改MFC的图标
- Windows RPC编程入门(已动手实践按红体字部分修改可以正常运行)
- Windows锁定计算机C代码编程实现
- Windows 编程[22] - 菜单选择与画刷修改
- Windows 7系统中如何查看和修改计算机名、域和工作组? 方法介绍
- windows 下批处理修改 计算机名 用于系统封装或虚拟化简单模板
- windows 不能在本地计算机启动apache2 的解决方法(不是修改端口)
- qt编程修改windows登陆界面时遇到的问题
- Windows锁定计算机C代码编程实现
- windows编程之内存数据修改
- 编程修改Windows用户密码
- ubuntu修改计算机名和加入windows工作组
- 从零开始,学习windows编程(5)--修改入口不为mainCRTStartup
- Windows高级编程之线程调度、优先级和亲缘性
- windows编程系列学习
- Windows 声音处理编程(基于winmm.dll)(3)
- windows编程入门之消息