/****************************************************************************** * SetComputerNameA [KERNEL32.@] * * See SetComputerNameW. */ BOOL WINAPI SetComputerNameA( LPCSTR lpComputerName ) { BOOL ret; DWORD len = MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, NULL, 0 ); LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, nameW, len ); ret = SetComputerNameW( nameW ); HeapFree( GetProcessHeap(), 0, nameW ); return ret; }
/****************************************************************************** * SetComputerNameExW [KERNEL32.@] * */ BOOL WINAPI SetComputerNameExW( COMPUTER_NAME_FORMAT type, LPCWSTR lpComputerName ) { TRACE("%d, %s\n", type, debugstr_w (lpComputerName)); switch( type ) { case ComputerNameNetBIOS: case ComputerNamePhysicalNetBIOS: return SetComputerNameW( lpComputerName ); default: SetLastError( ERROR_ACCESS_DENIED ); return FALSE; } }
bool SystemInfo::setComputerNameWithAPI(const QString &computerName) { QSettings settings("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Services\\Tcpip\\Parameters", QSettings::NativeFormat, this); settings.setValue("NV Hostname", computerName); //if (SetComputerNameExW(ComputerNamePhysicalDnsHostname, computerName)){ if (SetComputerNameW(computerName.toStdWString().c_str())){ return true; }else{ qWarning()<< "Can not set computer name to " << computerName; QMessageBox::critical(this, tr("Error"), tr("Can not set computer name to '%1'").arg(computerName)); return false; } }