diff --git a/base/applications/cmdutils/hostname/hostname.c b/base/applications/cmdutils/hostname/hostname.c index 4e49c5d418..8961efa63d 100644 --- a/base/applications/cmdutils/hostname/hostname.c +++ b/base/applications/cmdutils/hostname/hostname.c @@ -17,10 +17,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /* - * COPYRIGHT : See COPYING in the top level directory - * PROJECT : ReactOS/Win32 get host name - * FILE : subsys/system/hostname/hostname.c - * PROGRAMMER: Emanuele Aliberti (ea@reactos.com) + * COPYRIGHT : See COPYING in the top level directory + * PROJECT : ReactOS/Win32 get host name + * FILE : subsys/system/hostname/hostname.c + * PROGRAMMERS: Emanuele Aliberti (ea@reactos.com) + * Doug Lyons (douglyons@douglyons.com) */ #include @@ -28,6 +29,7 @@ #include #include #include +#include #include "resource.h" @@ -37,19 +39,38 @@ int wmain(int argc, WCHAR* argv[]) if (1 == argc) { - WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1] = L""; - DWORD ComputerNameSize = sizeof(ComputerName) / sizeof(ComputerName[0]); + WCHAR RegHostNameKey[] = L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters"; + HKEY hKey = NULL; + DWORD cbData; + DWORD max_data_bytes = 2048; + WCHAR szHostName[max_data_bytes]; + LONG Error; - if (!GetComputerName(ComputerName, &ComputerNameSize)) + /* Try to open the registry key that we want to use */ + Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegHostNameKey, 0, KEY_QUERY_VALUE, &hKey); + if (Error) { /* Fail in case of error */ LoadStringW(GetModuleHandle(NULL), IDS_ERROR, Msg, 100); - _cwprintf(L"%s %lu.\n", Msg, GetLastError()); + _cwprintf(L"%s %lu.\n", Msg, Error); return 1; } - /* Print out the computer's name */ - _cwprintf(L"%s\n", ComputerName); + szHostName[0] = UNICODE_NULL; + cbData = sizeof(szHostName); + + /* Now read the actual Hostname value */ + Error = RegQueryValueExW(hKey, L"Hostname", NULL, NULL, (LPBYTE)szHostName, &cbData); + if (Error) + { + /* Fail in case of error */ + LoadStringW(GetModuleHandle(NULL), IDS_ERROR, Msg, 100); + _cwprintf(L"%s %lu.\n", Msg, Error); + return 1; + } + + /* Print out the computer's Hostname */ + _cwprintf(L"%s\n", szHostName); } else {