From 7105ca622d1841aacde6d91565f9d4b479205fc5 Mon Sep 17 00:00:00 2001 From: computezrmle <57127745+computezrmle@users.noreply.github.com> Date: Tue, 8 Feb 2022 21:00:28 +0100 Subject: [PATCH 1/2] forward rtc setting from host to guest --- samples/vboxwrapper/vbox_vboxmanage.cpp | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index dbf99abc32..a479f7ee23 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -246,6 +246,11 @@ namespace vboxmanage { command = "modifyvm \"" + vm_name + "\" "; command += "--acpi on "; command += "--ioapic on "; + if (is_hostrtc_set_to_utc()) { + command += "--rtcuseutc on "; + } else { + command += "--rtcuseutc off "; + } retval = vbm_popen(command, output, "modifychipset"); if (retval) return retval; @@ -2072,6 +2077,46 @@ namespace vboxmanage { if (vm_pid) { setpriority(PRIO_PROCESS, vm_pid, PROCESS_NORMAL_PRIORITY); } +#endif + } + + bool VBOX_VM::is_hostrtc_set_to_utc() { +#ifdef _WIN32 + bool rtc_is_set_to_utc = false; + LONG lReturnValue; + HKEY hkSetupHive; + + // If the key is present and set to "1" assume the host's rtc is set to UTC. + // Otherwise or in case of an error assume the host's rtc is set to localtime. + lReturnValue = RegOpenKeyEx( + HKEY_LOCAL_MACHINE, + _T("SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"), + 0, + KEY_READ, + &hkSetupHive + ); + + if (lReturnValue == ERROR_SUCCESS) { + DWORD dwvalue = 0; + DWORD dwsize = sizeof(DWORD); + + lReturnValue = RegQueryValueEx( + hkSetupHive, + _T("RealTimeIsUniversal"), + NULL, + NULL, + (LPBYTE)&dwvalue, + &dwsize + ); + + if (lReturnValue == ERROR_SUCCESS && dwvalue == 1) rtc_is_set_to_utc = true; + } + + if (hkSetupHive) RegCloseKey(hkSetupHive); + return rtc_is_set_to_utc; +#else + // Non-Windows Systems usually set their rtc to UTC. + return true; #endif } } From 9acaada1ca2ffaab226dc6b832d38d09b93965a6 Mon Sep 17 00:00:00 2001 From: computezrmle <57127745+computezrmle@users.noreply.github.com> Date: Tue, 8 Feb 2022 21:04:02 +0100 Subject: [PATCH 2/2] forward rtc setting from host to guest --- samples/vboxwrapper/vbox_vboxmanage.h | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/vboxwrapper/vbox_vboxmanage.h b/samples/vboxwrapper/vbox_vboxmanage.h index 09beebd24d..2707ba768f 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.h +++ b/samples/vboxwrapper/vbox_vboxmanage.h @@ -52,6 +52,7 @@ namespace vboxmanage { bool is_disk_image_registered(); bool is_extpack_installed(); bool is_virtualbox_installed(); + bool is_hostrtc_set_to_utc(); int get_install_directory(std::string& dir); int get_version_information(std::string& version_raw, std::string& version_display);