ReactOS 0.4.15-dev-7953-g1f49173
GetComputerNameEx.c File Reference
#include "precomp.h"
Include dependency graph for GetComputerNameEx.c:

Go to the source code of this file.

Functions

static VOID TestGetComputerNameEx (_In_ COMPUTER_NAME_FORMAT NameType)
 
static LSTATUS ReadRegistryValue (PCHAR ValueName, PCHAR Value)
 
static LSTATUS ReadRegistryComputerNameValue (PCHAR ValueName, PCHAR Value)
 
static LSTATUS WriteRegistryValue (PCHAR ValueName, PCHAR Value)
 
static LSTATUS DeleteRegistryValue (PCHAR ValueName)
 
static VOID TestReturnValues ()
 
 START_TEST (GetComputerNameEx)
 

Function Documentation

◆ DeleteRegistryValue()

static LSTATUS DeleteRegistryValue ( PCHAR  ValueName)
static

Definition at line 303 of file GetComputerNameEx.c.

304{
306 HKEY ParametersKey;
307
308 /* Open the database path key */
310 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
311 0,
312 KEY_WRITE,
313 &ParametersKey);
314 if (ErrorCode == NO_ERROR)
315 {
316 /* Read the actual path */
317 ErrorCode = RegDeleteValueA(ParametersKey, ValueName);
318
319 /* Close the key */
320 RegCloseKey(ParametersKey);
321 }
322 return ErrorCode;
323}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define NO_ERROR
Definition: dderror.h:5
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define KEY_WRITE
Definition: nt_native.h:1031
int32_t INT
Definition: typedefs.h:58
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by TestReturnValues().

◆ ReadRegistryComputerNameValue()

static LSTATUS ReadRegistryComputerNameValue ( PCHAR  ValueName,
PCHAR  Value 
)
static

Definition at line 233 of file GetComputerNameEx.c.

234{
236 HKEY ParametersKey;
237 DWORD RegType;
238 DWORD RegSize = 0;
239
240 /* Open the database path key */
242 "System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName",
243 0,
244 KEY_READ,
245 &ParametersKey);
246 if (ErrorCode == NO_ERROR)
247 {
248 /* Read the actual path */
249 ErrorCode = RegQueryValueExA(ParametersKey,
250 ValueName,
251 NULL,
252 &RegType,
253 NULL,
254 &RegSize);
255 if (RegSize)
256 {
257 /* Read the actual path */
258 ErrorCode = RegQueryValueExA(ParametersKey,
259 ValueName,
260 NULL,
261 &RegType,
262 (LPBYTE)Value,
263 &RegSize);
264 }
265
266 /* Close the key */
267 RegCloseKey(ParametersKey);
268 }
269 return ErrorCode;
270}
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
unsigned long DWORD
Definition: ntddk_ex.h:95
#define KEY_READ
Definition: nt_native.h:1023
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by TestReturnValues().

◆ ReadRegistryValue()

static LSTATUS ReadRegistryValue ( PCHAR  ValueName,
PCHAR  Value 
)
static

Definition at line 192 of file GetComputerNameEx.c.

193{
195 HKEY ParametersKey;
196 DWORD RegType;
197 DWORD RegSize = 0;
198
199 /* Open the database path key */
201 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
202 0,
203 KEY_READ,
204 &ParametersKey);
205 if (ErrorCode == NO_ERROR)
206 {
207 /* Read the actual path */
208 ErrorCode = RegQueryValueExA(ParametersKey,
209 ValueName,
210 NULL,
211 &RegType,
212 NULL,
213 &RegSize);
214 if (RegSize)
215 {
216 /* Read the actual path */
217 ErrorCode = RegQueryValueExA(ParametersKey,
218 ValueName,
219 NULL,
220 &RegType,
221 (LPBYTE)Value,
222 &RegSize);
223 }
224
225 /* Close the key */
226 RegCloseKey(ParametersKey);
227 }
228 return ErrorCode;
229}

Referenced by TestReturnValues().

◆ START_TEST()

START_TEST ( GetComputerNameEx  )

Definition at line 584 of file GetComputerNameEx.c.

585{
586 TestGetComputerNameEx(ComputerNameNetBIOS);
587 TestGetComputerNameEx(ComputerNameDnsHostname);
588 TestGetComputerNameEx(ComputerNameDnsDomain);
589 //TestGetComputerNameEx(ComputerNameDnsFullyQualified);
590 TestGetComputerNameEx(ComputerNamePhysicalNetBIOS);
591 TestGetComputerNameEx(ComputerNamePhysicalDnsHostname);
592 TestGetComputerNameEx(ComputerNamePhysicalDnsDomain);
593 //TestGetComputerNameEx(ComputerNamePhysicalDnsFullyQualified);
595}
static VOID TestReturnValues()
static VOID TestGetComputerNameEx(_In_ COMPUTER_NAME_FORMAT NameType)

◆ TestGetComputerNameEx()

static VOID TestGetComputerNameEx ( _In_ COMPUTER_NAME_FORMAT  NameType)
static

Definition at line 12 of file GetComputerNameEx.c.

14{
15 WCHAR Reference[128];
16 DWORD ReferenceLen;
17 WCHAR BufferW[128];
18 CHAR BufferA[128];
19 BOOL Ret;
20 DWORD Size;
22 ULONG i;
23
24 Size = RTL_NUMBER_OF(Reference);
25 Ret = GetComputerNameExW(NameType, Reference, &Size);
26 ok(Ret == TRUE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
27 if (!Ret)
28 {
29 skip("[%d] Failed to get reference string\n", NameType);
30 return;
31 }
32 trace("[%d] Reference is %ls\n", NameType, Reference);
33 ReferenceLen = lstrlenW(Reference);
34 ok(ReferenceLen < RTL_NUMBER_OF(Reference),
35 "[%d] Unexpected ReferenceLen %lu\n", NameType, ReferenceLen);
36 if (NameType != ComputerNameDnsDomain && NameType != ComputerNamePhysicalDnsDomain)
37 {
38 ok(ReferenceLen != 0, "[%d] Unexpected ReferenceLen %lu\n", NameType, ReferenceLen);
39 }
40 ok(Size == ReferenceLen, "[%d] Size is %lu, expected %lu\n", NameType, Size, ReferenceLen);
41
42 /* NULL buffer, NULL size */
43 StartSeh()
44 SetLastError(0xdeadbeef);
47 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
50 StartSeh()
51 SetLastError(0xdeadbeef);
54 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
57
58 /* NULL buffer, nonzero size */
59 Size = 0x55555555;
60 SetLastError(0xdeadbeef);
63 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
65 ok(Size == 0x55555555, "[%d] Got Size %lu\n", NameType, Size);
66
67 Size = 0x55555555;
68 SetLastError(0xdeadbeef);
71 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
73 ok(Size == 0x55555555, "[%d] Got Size %lu\n", NameType, Size);
74
75 /* non-NULL buffer, NULL size */
76 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
77 SetLastError(0xdeadbeef);
78 Ret = GetComputerNameExW(NameType, BufferW, NULL);
80 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
82 ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n", NameType, BufferW[0]);
83
84 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
85 SetLastError(0xdeadbeef);
86 Ret = GetComputerNameExA(NameType, BufferA, NULL);
88 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
90 ok(BufferA[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType, BufferA[0]);
91
92 /* NULL buffer, zero size */
93 Size = 0;
94 SetLastError(0xdeadbeef);
97 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
99 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
100
101 Size = 0;
102 SetLastError(0xdeadbeef);
105 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
107 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
108
109 /* non-NULL buffer, zero size */
110 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
111 Size = 0;
112 SetLastError(0xdeadbeef);
113 Ret = GetComputerNameExW(NameType, BufferW, &Size);
115 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
117 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
118 ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n", NameType, BufferW[0]);
119
120 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
121 Size = 0;
122 SetLastError(0xdeadbeef);
123 Ret = GetComputerNameExA(NameType, BufferA, &Size);
125 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
127 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
128 ok(BufferA[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType, BufferA[0]);
129
130 /* non-NULL buffer, too small size */
131 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
132 Size = ReferenceLen;
133 SetLastError(0xdeadbeef);
134 Ret = GetComputerNameExW(NameType, BufferW, &Size);
136 ok(Ret == FALSE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
138 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
139 if (NameType != ComputerNameNetBIOS && NameType != ComputerNamePhysicalNetBIOS)
140 {
141 if (ReferenceLen == 0)
142 {
143 ok(BufferW[0] == 0x5555, "[%d] BufferW[0] = 0x%x\n",
144 NameType, BufferW[0]);
145 }
146 else
147 {
148 ok(BufferW[0] == 0, "[%d] BufferW[0] = 0x%x\n",
149 NameType, BufferW[0]);
150 }
151 }
152 ok(BufferW[1] == 0x5555, "[%d] BufferW[1] = 0x%x\n", NameType, BufferW[1]);
153
154 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
155 Size = ReferenceLen;
156 SetLastError(0xdeadbeef);
157 Ret = GetComputerNameExA(NameType, BufferA, &Size);
159 ok(Ret == FALSE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
160 ok(Error == ERROR_MORE_DATA, "[%d] GetComputerNameExA returned error %lu\n", NameType, Error);
161 ok(Size == ReferenceLen + 1, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
162 ok(BufferA[0] == 0x55, "[%d] BufferA[0] = 0x%x\n", NameType, BufferA[0]);
163
164 /* non-NULL buffer, exact size */
165 RtlFillMemory(BufferW, sizeof(BufferW), 0x55);
166 Size = ReferenceLen + 1;
167 Ret = GetComputerNameExW(NameType, BufferW, &Size);
168 ok(Ret == TRUE, "[%d] GetComputerNameExW returned %d\n", NameType, Ret);
169 ok(Size == ReferenceLen, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
170 ok(BufferW[ReferenceLen] == 0, "[%d] BufferW[ReferenceLen] = 0x%x\n", NameType, BufferW[ReferenceLen]);
171 ok(BufferW[ReferenceLen + 1] == 0x5555, "[%d] BufferW[ReferenceLen + 1] = 0x%x\n", NameType, BufferW[ReferenceLen + 1]);
172 ok(!wcscmp(BufferW, Reference), "[%d] '%ls' != '%ls'\n", NameType, BufferW, Reference);
173
174 RtlFillMemory(BufferA, sizeof(BufferA), 0x55);
175 Size = ReferenceLen + 1;
176 Ret = GetComputerNameExA(NameType, BufferA, &Size);
177 ok(Ret == TRUE, "[%d] GetComputerNameExA returned %d\n", NameType, Ret);
178 ok(Size == ReferenceLen, "[%d] Got Size %lu, expected %lu\n", NameType, Size, ReferenceLen + 1);
179 ok(BufferA[ReferenceLen] == 0, "[%d] BufferA[ReferenceLen] = 0x%x\n", NameType, BufferA[ReferenceLen]);
180 ok(BufferA[ReferenceLen + 1] == 0x55, "[%d] BufferA[ReferenceLen + 1] = 0x%x\n", NameType, BufferA[ReferenceLen + 1]);
181 for (i = 0; i < ReferenceLen; i++)
182 {
183 if (BufferA[i] != Reference[i])
184 {
185 ok(0, "[%d] BufferA[%lu] = 0x%x, expected 0x%x\n", NameType, i, BufferA[i], Reference[i]);
186 }
187 }
188}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn UINT32 *TableIdx UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 NameType
Definition: acpixf.h:658
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
BOOL Error
Definition: chkdsk.c:66
BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize)
Definition: compname.c:216
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define lstrlenW
Definition: compat.h:750
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT, LPSTR, LPDWORD)
Definition: compname.c:376
#define d
Definition: ke_i.h:81
if(dx< 0)
Definition: linetemp.h:194
#define error(str)
Definition: mkdosfs.c:1605
BOOL expected
Definition: store.c:2063
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ TestReturnValues()

static VOID TestReturnValues ( )
static

Definition at line 328 of file GetComputerNameEx.c.

329{
330 CHAR OrigNetBIOS[128];
331 CHAR OrigHostname[128];
332 CHAR OrigDomainName[128];
333 CHAR OrigDhcpHostname[128];
334 CHAR OrigDhcpDomainName[128];
335 BOOL OrigNetBIOSExists;
336 BOOL OrigHostnameExists;
337 BOOL OrigDomainNameExists;
338 BOOL OrigDhcpHostnameExists;
339 BOOL OrigDhcpDomainNameExists;
340 CHAR ComputerName[128];
341 DWORD ComputerNameSize = 0;
343 BOOL Ret;
344
345 memset(OrigNetBIOS, 0, sizeof(OrigNetBIOS));
346 memset(OrigHostname, 0, sizeof(OrigHostname));
347 memset(OrigDomainName, 0, sizeof(OrigDomainName));
348 memset(OrigDhcpHostname, 0, sizeof(OrigDhcpHostname));
349 memset(OrigDhcpDomainName, 0, sizeof(OrigDhcpDomainName));
350 /* read current registry values */
351 ErrorCode = ReadRegistryComputerNameValue("ComputerName", OrigNetBIOS);
352 ok(ErrorCode == ERROR_SUCCESS, "Failed to read registry key ComputerName %d\n", ErrorCode);
353 OrigNetBIOSExists = ErrorCode == STATUS_SUCCESS;
354 ErrorCode = ReadRegistryValue("Hostname", OrigHostname);
355 ok(ErrorCode == ERROR_SUCCESS, "Failed to read registry key Hostname %d\n", ErrorCode);
356 OrigHostnameExists = ErrorCode == STATUS_SUCCESS;
357 ErrorCode = ReadRegistryValue("Domain", OrigDomainName);
358 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DomainName %d\n", ErrorCode);
359 OrigDomainNameExists = ErrorCode == STATUS_SUCCESS;
360 ErrorCode = ReadRegistryValue("DhcpHostname", OrigDhcpHostname);
361 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DhcpHostname %d\n", ErrorCode);
362 OrigDhcpHostnameExists = ErrorCode == STATUS_SUCCESS;
363 ErrorCode = ReadRegistryValue("DhcpDomain", OrigDhcpDomainName);
364 ok(ErrorCode == ERROR_SUCCESS || ErrorCode == ERROR_FILE_NOT_FOUND, "Failed to read registry key DhcpDomainName %d\n", ErrorCode);
365 OrigDhcpDomainNameExists = ErrorCode == STATUS_SUCCESS;
366
367 trace("Starting values:\n");
368 trace("NetBIOS: %s, exists %s\n", OrigNetBIOS, OrigNetBIOSExists ? "yes" : "no");
369 trace("Hostname: %s, exists %s\n", OrigHostname, OrigHostnameExists ? "yes" : "no");
370 trace("Domain: %s, exists %s\n", OrigDomainName, OrigDomainNameExists ? "yes" : "no");
371 trace("DhcpHostname: %s, exists %s\n", OrigDhcpHostnameExists ? OrigDhcpHostname : "", OrigDhcpHostnameExists ? "yes" : "no");
372 trace("DhcpDomain: %s, exists %s\n", OrigDhcpDomainNameExists ? OrigDhcpDomainName : "", OrigDhcpDomainNameExists ? "yes" : "no");
373
374 /* ComputerNamePhysicalNetBIOS */
375 ComputerNameSize = 0;
376 StartSeh()
377 GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
378 if (ComputerNameSize)
379 {
380 Ret = GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
381 ok(Ret, "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
382 }
383 else
384 {
385 memset(ComputerName, 0, sizeof(ComputerName));
386 }
387 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
389
390 /* ComputerNamePhysicalDnsHostname */
391 ComputerNameSize = 0;
392 StartSeh()
393 GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
394 if (ComputerNameSize)
395 {
396 Ret = GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
397 ok(Ret, "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
398 }
399 else
400 {
401 memset(ComputerName, 0, sizeof(ComputerName));
402 }
403 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
405
406 /* ComputerNamePhysicalDnsDomain */
407 ComputerNameSize = 0;
408 StartSeh()
409 GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
410 if (ComputerNameSize)
411 {
412 Ret = GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
413 ok(Ret, "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
414 }
415 else
416 {
417 memset(ComputerName, 0, sizeof(ComputerName));
418 }
419 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
421 ComputerNameSize = 0;
422
423 /* ComputerNameNetBIOS */
424 StartSeh()
425 GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
426 if (ComputerNameSize)
427 {
428 Ret = GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
429 ok(Ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
430 }
431 else
432 {
433 memset(ComputerName, 0, sizeof(ComputerName));
434 }
435 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
437
438 /* ComputerNameDnsHostname */
439 ComputerNameSize = 0;
440 StartSeh()
441 GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
442 if (ComputerNameSize)
443 {
444 Ret = GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
445 ok(Ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
446 }
447 else
448 {
449 memset(ComputerName, 0, sizeof(ComputerName));
450 }
451 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
453
454 /* ComputerNameDnsDomain */
455 ComputerNameSize = 0;
456 StartSeh()
457 GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
458 if (ComputerNameSize)
459 {
460 Ret = GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
461 ok(Ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
462 }
463 else
464 {
465 memset(ComputerName, 0, sizeof(ComputerName));
466 }
467 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
469
470 ErrorCode = WriteRegistryValue("DhcpHostname", "testdhcproshost");
471 ok(ErrorCode == ERROR_SUCCESS, "Failed to write registry key DhcpHostname %d\n", ErrorCode);
472 ErrorCode = WriteRegistryValue("DhcpDomain", "testrosdomain");
473 ok(ErrorCode == ERROR_SUCCESS, "Failed to write registry key DhcpDomainName %d\n", ErrorCode);
474
475 /* ComputerNamePhysicalNetBIOS */
476 ComputerNameSize = 0;
477 StartSeh()
478 GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
479 if (ComputerNameSize)
480 {
481 Ret = GetComputerNameExA(ComputerNamePhysicalNetBIOS, ComputerName, &ComputerNameSize);
482 ok(Ret, "GetComputerNameExA(ComputerNamePhysicalNetBIOS) failed with %ld\n", GetLastError());
483 }
484 else
485 {
486 memset(ComputerName, 0, sizeof(ComputerName));
487 }
488 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNamePhysicalNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
490
491 /* ComputerNamePhysicalDnsHostname */
492 ComputerNameSize = 0;
493 StartSeh()
494 GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
495 if (ComputerNameSize)
496 {
497 Ret = GetComputerNameExA(ComputerNamePhysicalDnsHostname, ComputerName, &ComputerNameSize);
498 ok(Ret, "GetComputerNameExA(ComputerNamePhysicalDnsHostname) failed with %ld\n", GetLastError());
499 }
500 else
501 {
502 memset(ComputerName, 0, sizeof(ComputerName));
503 }
504 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNamePhysicalDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
506
507 /* ComputerNamePhysicalDnsDomain */
508 ComputerNameSize = 0;
509 StartSeh()
510 GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
511 if (ComputerNameSize)
512 {
513 Ret = GetComputerNameExA(ComputerNamePhysicalDnsDomain, ComputerName, &ComputerNameSize);
514 ok(Ret, "GetComputerNameExA(ComputerNamePhysicalDnsDomain) failed with %ld\n", GetLastError());
515 }
516 else
517 {
518 memset(ComputerName, 0, sizeof(ComputerName));
519 }
520 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNamePhysicalDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
522 ComputerNameSize = 0;
523
524 /* ComputerNameNetBIOS */
525 StartSeh()
526 GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
527 if (ComputerNameSize)
528 {
529 Ret = GetComputerNameExA(ComputerNameNetBIOS, ComputerName, &ComputerNameSize);
530 ok(Ret, "GetComputerNameExA(ComputerNameNetBIOS) failed with %ld\n", GetLastError());
531 }
532 else
533 {
534 memset(ComputerName, 0, sizeof(ComputerName));
535 }
536 ok(strcmp(ComputerName, OrigNetBIOS) == 0, "ComputerNameNetBIOS doesn't match registry value '%s' != '%s'\n", ComputerName, OrigNetBIOS);
538
539 /* ComputerNameDnsHostname */
540 ComputerNameSize = 0;
541 StartSeh()
542 GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
543 if (ComputerNameSize)
544 {
545 Ret = GetComputerNameExA(ComputerNameDnsHostname, ComputerName, &ComputerNameSize);
546 ok(Ret, "GetComputerNameExA(ComputerNameDnsHostname) failed with %ld\n", GetLastError());
547 }
548 else
549 {
550 memset(ComputerName, 0, sizeof(ComputerName));
551 }
552 ok(strcmp(ComputerName, OrigHostname) == 0, "ComputerNameDnsHostname doesn't match registry value '%s' != '%s'\n", ComputerName, OrigHostname);
554
555 /* ComputerNameDnsDomain */
556 ComputerNameSize = 0;
557 StartSeh()
558 GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
559 if (ComputerNameSize)
560 {
561 Ret = GetComputerNameExA(ComputerNameDnsDomain, ComputerName, &ComputerNameSize);
562 ok(Ret, "GetComputerNameExA(ComputerNameDnsDomain) failed with %ld\n", GetLastError());
563 }
564 else
565 {
566 memset(ComputerName, 0, sizeof(ComputerName));
567 }
568 ok(strcmp(ComputerName, OrigDomainName) == 0, "ComputerNameDnsDomain doesn't match registry value '%s' != '%s'\n", ComputerName, OrigDomainName);
570
571 /* restore registry values */
572 if (OrigDhcpHostnameExists)
573 ErrorCode = WriteRegistryValue("DhcpHostname", OrigDhcpHostname);
574 else
575 ErrorCode = DeleteRegistryValue("DhcpHostname");
576 ok(ErrorCode == ERROR_SUCCESS, "Failed to restore registry key DhcpHostname %d\n", ErrorCode);
577 if (OrigDhcpDomainNameExists)
578 ErrorCode = WriteRegistryValue("DhcpDomain", OrigDhcpDomainName);
579 else
580 ErrorCode = DeleteRegistryValue("DhcpDomain");
581 ok(ErrorCode == ERROR_SUCCESS, "Failed to restore registry key DhcpDomainName %d\n", ErrorCode);
582}
static LSTATUS DeleteRegistryValue(PCHAR ValueName)
static LSTATUS WriteRegistryValue(PCHAR ValueName, PCHAR Value)
static LSTATUS ReadRegistryComputerNameValue(PCHAR ValueName, PCHAR Value)
static LSTATUS ReadRegistryValue(PCHAR ValueName, PCHAR Value)
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define memset(x, y, z)
Definition: compat.h:39

Referenced by START_TEST().

◆ WriteRegistryValue()

static LSTATUS WriteRegistryValue ( PCHAR  ValueName,
PCHAR  Value 
)
static

Definition at line 274 of file GetComputerNameEx.c.

275{
277 HKEY ParametersKey;
278
279 /* Open the database path key */
281 "System\\CurrentControlSet\\Services\\Tcpip\\Parameters",
282 0,
283 KEY_WRITE,
284 &ParametersKey);
285 if (ErrorCode == NO_ERROR)
286 {
287 /* Read the actual path */
288 ErrorCode = RegSetValueExA(ParametersKey,
289 ValueName,
290 0,
291 REG_SZ,
292 (LPBYTE)Value,
293 lstrlenA(Value) + 1);
294
295 /* Close the key */
296 RegCloseKey(ParametersKey);
297 }
298 return ErrorCode;
299}
LONG WINAPI RegSetValueExA(HKEY hKey, LPCSTR lpValueName, DWORD Reserved, DWORD dwType, CONST BYTE *lpData, DWORD cbData)
Definition: reg.c:4799
#define REG_SZ
Definition: layer.c:22
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145

Referenced by TestReturnValues().