Exemple #1
0
		// Retrieves the account names (domain\user) for all local accounts
        std::vector<UserProfile> GetLocalProfiles()
		{
            Registry reg;
			DWORD ret = reg.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", Registry::Mode::Read);
            if (ret != ERROR_SUCCESS) throw SysError(ret);

            std::vector<std::wstring> profileSids;
			ret = reg.EnumKeys(profileSids);
			if (ret != ERROR_SUCCESS) throw SysError(ret);
			
			std::vector<UserProfile> accounts;
			for (auto const& sidStr : profileSids)
			{
                UserProfile profile{};
				profile.sid = sidStr;
				Registry::TryReadString(reg.Key(), sidStr, L"ProfileImagePath", profile.path);
				/*DWORD ret = */Security::SidToAccountName(sidStr, profile.name, profile.domain);
                accounts.push_back(profile);
			}

			return accounts;
		}		
Exemple #2
0
			DWORD Init()
			{
				Registry reg;
				auto result = reg.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", Registry::Mode::Read);
				if (result != ERROR_SUCCESS)
				{
					return result;
				}
				reg.TryReadString(L"CurrentBuildNumber", CurrentBuildNumber);
				reg.TryReadDword(L"CurrentMajorVersionNumber", CurrentMajorVersionNumber);
				reg.TryReadDword(L"CurrentMinorVersionNumber", CurrentMinorVersionNumber);	
                reg.TryReadString(L"CSDbuildNumber", CSDBuildNumber);
                reg.TryReadString(L"CSDVersion", ServicePack);
                auto pos = ServicePack.find_last_not_of(L"Service Pack ");
                if (pos != std::wstring::npos)
                {
                    ServicePack = L"SP" + ServicePack.substr(pos);
                }
                if (reg.TryReadString(L"BuildLabEx", BuildLabEx) != NO_ERROR)
                {
                    reg.TryReadString(L"BuildLab", BuildLabEx);
                }
				reg.TryReadString(L"CurrentVersion", CurrentVersion);
				reg.TryReadString(L"EditionId", EditionId);
				reg.TryReadString(L"ProductName", ProductName);
				if (CurrentMajorVersionNumber > 0)
				{
					CurrentVersion = std::to_wstring(CurrentMajorVersionNumber) + L"." + std::to_wstring(CurrentMinorVersionNumber);
				}
				else
				{
					reg.TryReadString(L"CurrentVersion", CurrentVersion);
				}

				Architecture = IsX64() ? std::wstring(L"x64") : std::wstring(L"x86");
				Language = GetDefaultLocaleName();

				return ERROR_SUCCESS;
			}