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 M开发者_如何学CY-PC
Any idea why the computer name at Control Panel\System and Security\System has not been updated?
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
精彩评论