Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3605)

Unified Diff: base/win/win_util.cc

Issue 2581353002: Use the Windows MDM API to check if the machine is being managed. (Closed)
Patch Set: Fix components tests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/win/win_util.cc
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index 3b7d3195ac6c0b2622ef39c263cf2479d6c4606f..838891102df72b0f6dc1dcddf7cd5777b9922a0d 100644
--- a/base/win/win_util.cc
+++ b/base/win/win_util.cc
@@ -10,6 +10,7 @@
#include <shobjidl.h> // Must be before propkey.
#include <initguid.h>
#include <inspectable.h>
+#include <mdmregistration.h>
#include <propkey.h>
#include <propvarutil.h>
#include <psapi.h>
@@ -535,6 +536,31 @@ bool IsEnrolledToDomain() {
return g_domain_state == ENROLLED;
}
+bool IsDeviceRegisteredWithMdm() {
+ using IsDeviceRegisteredWithManagementFunction =
+ decltype(&IsDeviceRegisteredWithManagement);
+
+ static IsDeviceRegisteredWithManagementFunction fn = nullptr;
+ if (!fn) {
+ HMODULE mdm_dll = ::LoadLibrary(L"MDMRegistration.dll");
+ fn = reinterpret_cast<IsDeviceRegisteredWithManagementFunction>(
+ ::GetProcAddress(mdm_dll, "IsDeviceRegisteredWithManagement"));
+ if (!fn) {
+ return false;
+ }
+ }
+
+ BOOL is_managed = false;
+ HRESULT hr = fn(&is_managed, 0, nullptr);
+ LOG(ERROR) << "*** rogerta: IsDeviceRegisteredWithMdm: "
+ << (bool)((hr) && is_managed);
+ return SUCCEEDED(hr) && is_managed;
+}
+
+bool IsEnterpriseUser() {
+ return IsEnrolledToDomain() || IsDeviceRegisteredWithMdm();
+}
+
void SetDomainStateForTesting(bool state) {
g_domain_state = state ? ENROLLED : NOT_ENROLLED;
}

Powered by Google App Engine
This is Rietveld 408576698