After the company's software custom department works, the computer name issue has been studied. He has some experience, written a tool implementation. Not only change the computer name, the NetBIOS name is also updated at the same time .WIN2000 and WinXP test passed.
#include "stdafx.h" #include "chgcompname.h"
#ifdef _debug # define new debug_new # undef this_filestatic char this_file [] = __file __; # ENDIF
Extern "C" int GETOPT (int, char * const *, const char *); Extern "C" char * OPTARG; /// the one and only application objection Object
CWINAPPPP;
Using namespace std; void usage (int _tmain (int Argc, tchar * argv [], * 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. "<< end1; // initialize mfc and print and error on five (! AFXWININIT (:: getModuleHandle (null), null, :: getcommandline (), 0)) {// Todo: Change Error Code To Suit Your Needs Cerr <<_T ("Fatal Error: MFC Initialization Faled") << ELSE {IF (argc == 1) {usage (argv [0]); return 2; car temp = null; cstract scomputername (""); cstract sworkgroupname ("); while (Temp = getopt (Argc, Argv, "C:? H")))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))! = - 1) {Switch (Temp) {CASE 'C': scomputername = Optarg; Break; Default: usage (argv [0]); Return 2; } }
IF (setcomputernameex) // change the computer name, this is the key. {COUT << "The Computer Name Has Been successful change 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);