开发者

Problem with SetComputerName Function

开发者 https://www.devze.com 2023-01-14 19:29 出处:网络
I used following line of code to change my computer name: std::string mystr="MY-PC" bSuccess = SetComputerNameA(mystr.c_str());

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

0

精彩评论

暂无评论...
验证码 换一张
取 消