Beispiel #1
0
// Returns a `Try` of the result of attempting to set the `hostname`.
inline Try<Nothing> setHostname(const std::string& hostname)
{
  if (SetComputerName(hostname.c_str()) == 0) {
    return WindowsError();
  }

  return Nothing();
}
Beispiel #2
0
void setname(char *name) 
{
	HKEY hKey;

	if(!SetComputerName(name)) {
		fprintf(stderr, "Error setting computer name\n");
	}

	// This registry entry is only valid for NT/XP/Vista
	RegOpenKeyEx( HKEY_LOCAL_MACHINE,
			"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
			0, KEY_SET_VALUE, &hKey );
	
	if(RegSetValueEx(hKey, "Hostname", 0, REG_SZ, name, strlen(name)+1))
	{
		fprintf(stderr, "Error setting hostname\n");
	}
	if(RegSetValueEx(hKey, "NV Hostname", 0, REG_SZ, name, strlen(name)+1))
	{
		fprintf(stderr, "Error setting NV hostname\n");
	}
}