views:

17

answers:

1

I used following line of code to change my computer name:

std::string mystr="MY-PC"
bSuccess = SetComputerNameA(mystr.c_str());
if( bSuccess == 0 )
    printf("Unable to change computer name | ERROR %d |", GetLastError());
else
        printf("Name changed successfully");

Upon executing the program, 'Name changed successfully' message appeared. Following registry items were found to have the update computer name

HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName

HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName

After restarting my computer, I checked the computer name from Control Panel\System and Security\System. To my surprise it still have the old name.

Checked the registry again which contain the new name i.e MY-PC

Any idea why the computer name at Control Panel\System and Security\System has not been updated?

+1  A: 

The SetComputerNameA function only sets the netbios name. You need to use the SetComputerNameEx I think.

BOOL WINAPI SetComputerNameEx(
  __in  COMPUTER_NAME_FORMAT NameType,
  __in  LPCTSTR lpBuffer
);

With the COMPUTER_NAME_FORMAT as ComputerNamePhysicalDnsHostname

Preet Sangha