Index: apitests/kernel32/CMakeLists.txt =================================================================== --- apitests/kernel32/CMakeLists.txt (revision 71259) +++ apitests/kernel32/CMakeLists.txt (working copy) @@ -9,6 +9,7 @@ lstrcpynW.c MultiByteToWideChar.c PrivMoveFileIdentityW.c + SetComputerNameExW.c SetCurrentDirectory.c SetUnhandledExceptionFilter.c TerminateProcess.c @@ -19,5 +20,5 @@ add_executable(kernel32_apitest ${SOURCE}) target_link_libraries(kernel32_apitest wine ${PSEH_LIB}) set_module_type(kernel32_apitest win32cui) -add_importlibs(kernel32_apitest gdi32 user32 shlwapi msvcrt kernel32 ntdll) +add_importlibs(kernel32_apitest advapi32 gdi32 user32 shlwapi msvcrt kernel32 ntdll) add_cd_file(TARGET kernel32_apitest DESTINATION reactos/bin FOR all) Index: apitests/kernel32/SetComputerNameExW.c =================================================================== --- apitests/kernel32/SetComputerNameExW.c (revision 0) +++ apitests/kernel32/SetComputerNameExW.c (working copy) @@ -0,0 +1,98 @@ + /* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Tests for the SetComputerNameExW api + * PROGRAMMER: Víctor Martínez Calvo (vicmarcal@gmail.com) + */ +#include + +#define WIN32_NO_STATUS +#include +#include + +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#include + + + +START_TEST(SetComputerNameExW) +{ + LONG Status; + BOOL ret; + HKEY hKeyHN; + HKEY hKeyCN; + DWORD pcbData; + DWORD cbData = 0; + WCHAR RegistryHostName[] = L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters"; + WCHAR RegistryComputerName[] = L"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName"; + WCHAR pvHostNameOld[MAX_PATH] = {0}; + WCHAR pvComputerNameOld[MAX_PATH] = {0}; + WCHAR pvHostNameNew[MAX_PATH] = {0}; + WCHAR pvComputerNameNew[MAX_PATH] = {0}; + WCHAR NewName[] = L"SRVROSTEST"; + + //Open keys + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegistryHostName, 0, KEY_ALL_ACCESS, &hKeyHN) != ERROR_SUCCESS) + { + // failed to open key + return; + } + + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, RegistryComputerName, 0, KEY_ALL_ACCESS, &hKeyCN) != ERROR_SUCCESS) + { + // failed to open key + return; + } + + pcbData = sizeof(pvHostNameOld); + + // Retrieve current name from Hostname and Computername + Status = RegGetValueW(hKeyHN, NULL, L"Hostname", RRF_RT_REG_SZ, NULL, pvHostNameOld, &pcbData ); + ok( Status == ERROR_SUCCESS, "Expected to succeed, but failed with %d", Status); + if (Status) return; + ok( *pvHostNameOld, "pvHostNameOld is %S", pvHostNameOld); + + pcbData = sizeof(pvComputerNameOld); + Status = RegGetValueW(hKeyCN, NULL, L"ComputerName", RRF_RT_REG_SZ, NULL, pvComputerNameOld, &pcbData ); + ok( Status == ERROR_SUCCESS, "Expected to succeed, but failed with %d", Status); + if (Status) return; + ok( *pvComputerNameOld, "pvHostNameOld is %S", pvComputerNameOld); + + /* Change the value */ + ret = SetComputerNameExW(ComputerNamePhysicalDnsHostname, NewName); + ok( ret, "SetComputerNameExW failed with %d", GetLastError()); + + /* Check the new values */ + + // Hostname in Services\\Tcpip\\Parameters shouldn't change until next reboot. + pcbData = sizeof(pvHostNameNew); + Status = RegGetValueW(hKeyHN, NULL, L"Hostname", RRF_RT_REG_SZ, NULL, pvHostNameNew, &pcbData ); + if (Status) return; + ok( !wcscmp(pvHostNameNew, pvHostNameOld), "pvHostNameNew: %S It should be pvHostNameOld: %S ", pvHostNameNew, pvHostNameOld); + + // NV Hostname in Services\\Tcpip\\Parameters should have changed. + pcbData = sizeof(pvHostNameNew); + Status = RegGetValueW(hKeyHN, NULL, L"NV Hostname", RRF_RT_REG_SZ, NULL, pvHostNameNew, &pcbData ); + if (Status) return; + ok( !wcscmp(pvHostNameNew, NewName), "pvHostNameNew: %S It should be NewName: %S ", pvHostNameNew, NewName); + + // ComputerName in Control\\ComputerName\\ComputerName should have changed. + pcbData = sizeof(pvComputerNameNew); + Status = RegGetValueW(hKeyCN, NULL, L"ComputerName", RRF_RT_REG_SZ, NULL, pvComputerNameNew, &pcbData ); + if (Status) return; + ok( !wcscmp(pvComputerNameNew, NewName), "pvComputerNameNew: %S It should be NewName: %S ", pvComputerNameNew, NewName); + + /* Reset the registry values to the old ones */ + Status = RegSetValueExW(hKeyHN, L"NV Hostname", 0, REG_SZ, pvHostNameOld, sizeof(pvHostNameOld)); + if (Status) return; + + Status = RegSetValueExW(hKeyCN, L"ComputerName", 0, REG_SZ, pvComputerNameOld, sizeof(pvComputerNameOld)); + if (Status) return; + + + //Close handles + RegCloseKey(hKeyCN); + RegCloseKey(hKeyHN); + +} Index: apitests/kernel32/testlist.c =================================================================== --- apitests/kernel32/testlist.c (revision 71259) +++ apitests/kernel32/testlist.c (working copy) @@ -13,6 +13,7 @@ extern void func_Mailslot(void); extern void func_MultiByteToWideChar(void); extern void func_PrivMoveFileIdentityW(void); +extern void func_SetComputerNameExW(void); extern void func_SetCurrentDirectory(void); extern void func_SetUnhandledExceptionFilter(void); extern void func_TerminateProcess(void); @@ -30,6 +31,7 @@ { "MailslotRead", func_Mailslot }, { "MultiByteToWideChar", func_MultiByteToWideChar }, { "PrivMoveFileIdentityW", func_PrivMoveFileIdentityW }, + { "SetComputerNameExW", func_SetComputerNameExW }, { "SetCurrentDirectory", func_SetCurrentDirectory }, { "SetUnhandledExceptionFilter", func_SetUnhandledExceptionFilter }, { "TerminateProcess", func_TerminateProcess },