Einzelnen Beitrag anzeigen

WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Set hostname - can't write to registry

  Alt 5. Apr 2012, 15:44
Delphi-Version: 2010
I'm trying change host name (like My Computer properties --> Computer Name).

I did this:

Delphi-Quellcode:
if OpenKey('SYSTEM\CurrentControlSet\services\Tcpip\Parameters', True) then
try
  WriteString('NV Hostname', FHostName);
  WriteString('Hostname', FHostName);
finally
  CloseKey;
end;
but raises exception that failed to set data for these values.

So, I tried this:

Delphi-Quellcode:
function SetComputerNameEx(NameType: TComputerNameFormat; lpComputerName: PWideChar): BOOL; stdcall;
  external 'kernel32.dllname 'SetComputerNameExW';

SetComputerNameEx(ComputerNamePhysicalDnsHostname, 'NewName');
Returns false. I'm administrator.
  Mit Zitat antworten Zitat