|
26 | 26 | #include "BinaryBuffer.h"
|
27 | 27 | #include "Utils/Time.h"
|
28 | 28 | #include "Utils/TypeTraits.h"
|
| 29 | +#include "Utils/Guard.h" |
29 | 30 |
|
30 | 31 | namespace fs = std::filesystem;
|
31 | 32 | using namespace std::string_view_literals;
|
@@ -1007,6 +1008,34 @@ HRESULT Orc::SystemDetails::GetUserLanguage(std::wstring& strLanguage)
|
1007 | 1008 | return S_OK;
|
1008 | 1009 | }
|
1009 | 1010 |
|
| 1011 | +Result<std::chrono::system_clock::time_point> Orc::SystemDetails::GetShutdownTimeFromRegistry() |
| 1012 | +{ |
| 1013 | + const wchar_t key[] = L"SYSTEM\\CurrentControlSet\\Control\\Windows"; |
| 1014 | + |
| 1015 | + Guard::RegistryHandle hKey; |
| 1016 | + auto status = RegOpenKeyW(HKEY_LOCAL_MACHINE, key, &hKey.value()); |
| 1017 | + if (status != ERROR_SUCCESS) |
| 1018 | + { |
| 1019 | + auto ec = Win32Error(status); |
| 1020 | + Log::Debug(L"Failed RegOpenKeyW (key: {}) [{}]", key, ec); |
| 1021 | + return ec; |
| 1022 | + } |
| 1023 | + |
| 1024 | + FILETIME shutdownTime; |
| 1025 | + const wchar_t value[] = L"ShutdownTime"; |
| 1026 | + DWORD valueType = 0L; |
| 1027 | + DWORD cbData = sizeof(shutdownTime); |
| 1028 | + status = RegQueryValueExW(hKey.value(), value, NULL, &valueType, (LPBYTE)&shutdownTime, &cbData); |
| 1029 | + if (status != ERROR_SUCCESS) |
| 1030 | + { |
| 1031 | + auto ec = Win32Error(status); |
| 1032 | + Log::Debug(L"Failed RegQueryValueExW (key: {}, value: {}) [{}]", key, value, ec); |
| 1033 | + return ec; |
| 1034 | + } |
| 1035 | + |
| 1036 | + return FromFileTime(shutdownTime); |
| 1037 | +} |
| 1038 | + |
1010 | 1039 | SystemDetails::DriveType SystemDetails::GetPathLocation(const std::wstring& strAnyPath)
|
1011 | 1040 | {
|
1012 | 1041 | WCHAR szVolume[ORC_MAX_PATH];
|
|
0 commit comments