@@ -241,6 +241,13 @@ static char THIS_FILE[] = __FILE__;
241
241
#define NT_APPS_LANGUAGE_VALUE _T ( " Language" )
242
242
#define NT_APPS_INSTALLDATE_VALUE _T ( " InstallDate" )
243
243
244
+ // Defines for retrieving AzureAD informations from registry
245
+ #define AZUREAD_KEY _T ( " SOFTWARE\\ Microsoft\\ IdentityStore\\ Cache" )
246
+ #define AZUREAD_SAMNAME_VALUE _T ( " SAMName" )
247
+ #define AZUREAD_DISPLAYNAME_VALUE _T ( " DisplayName" )
248
+ #define AZUREAD_PROVIDERNAME_VALUE _T ( " ProviderName" )
249
+
250
+
244
251
// ////////////////////////////////////////////////////////////////////
245
252
// Construction/Destruction
246
253
// ////////////////////////////////////////////////////////////////////
@@ -4535,4 +4542,135 @@ BOOL CRegistry::GetUser(CString &csUser) {
4535
4542
AddLog (_T (" \t Failed in call to <RegOpenKey> function for HKCU\\ %s !\n " ),
4536
4543
WIN10_LASTLOGGEDUSER_USER_KEY);
4537
4544
return FALSE ;
4545
+ }
4546
+
4547
+ BOOL CRegistry::IsAzureAd (CString &csDomain) {
4548
+ HKEY hKeyEnum,
4549
+ hKeyGroup,
4550
+ hKeyProperty,
4551
+ hKeyUserSid;
4552
+ CString csSubKey,
4553
+ csDomainAz = NOT_AVAILABLE;
4554
+ TCHAR szGroupName[256 ],
4555
+ szDeviceName[256 ],
4556
+ szUserSid[256 ];
4557
+ DWORD dwLength,
4558
+ dwMemory,
4559
+ dwIndexEnum = 0 ,
4560
+ dwIndexGroup = 0 ,
4561
+ dwIndexUser = 0 ;
4562
+ LONG lResult;
4563
+ FILETIME MyFileTime;
4564
+ UINT uIndex = 0 ;
4565
+ BOOL isAzure;
4566
+
4567
+ AddLog (_T (" Registry isAzureAD: Trying to find if the machine is connected to an AzureAD in HKLM\\ %s...\n " ), AZUREAD_KEY);
4568
+
4569
+ if (RegOpenKeyEx (m_hKey, AZUREAD_KEY, 0 , KEY_READ | KEY_WOW64_64KEY, &hKeyEnum) == ERROR_SUCCESS)
4570
+ {
4571
+ dwLength = 255 ;
4572
+ while ((lResult = RegEnumKeyEx (hKeyEnum, dwIndexEnum, szGroupName, &dwLength, 0 , NULL , 0 , &MyFileTime)) == ERROR_SUCCESS)
4573
+ {
4574
+ // For each group, enumerate user keys
4575
+ szGroupName[dwLength] = 0 ;
4576
+ csSubKey.Format (_T (" %s\\ %s" ), AZUREAD_KEY, szGroupName);
4577
+ if (RegOpenKeyEx (m_hKey, csSubKey, 0 , KEY_READ | KEY_WOW64_64KEY, &hKeyGroup) == ERROR_SUCCESS)
4578
+ {
4579
+ dwLength = 255 ;
4580
+ dwIndexGroup = 0 ;
4581
+ while ((lResult = RegEnumKeyEx (hKeyGroup, dwIndexGroup, szDeviceName, &dwLength, 0 , NULL , 0 , &MyFileTime)) == ERROR_SUCCESS)
4582
+ {
4583
+ // For each user, get property keys
4584
+ szDeviceName[dwLength] = 0 ;
4585
+ csSubKey.Format (_T (" %s\\ %s\\ %s" ), AZUREAD_KEY, szGroupName, szDeviceName);
4586
+ if (RegOpenKeyEx (m_hKey, csSubKey, 0 , KEY_READ | KEY_WOW64_64KEY, &hKeyProperty) == ERROR_SUCCESS)
4587
+ {
4588
+ dwLength = 255 ;
4589
+ dwIndexUser = 0 ;
4590
+ while ((lResult = RegEnumKeyEx (hKeyProperty, dwIndexUser, szUserSid, &dwLength, 0 , NULL , 0 , &MyFileTime)) == ERROR_SUCCESS)
4591
+ {
4592
+ // For each group, enumerate user keys
4593
+ szUserSid[dwLength] = 0 ;
4594
+ csSubKey.Format (_T (" %s\\ %s\\ %s\\ %s" ), AZUREAD_KEY, szGroupName, szDeviceName, szUserSid);
4595
+ if (RegOpenKeyEx (m_hKey, csSubKey, 0 , KEY_READ | KEY_WOW64_64KEY, &hKeyUserSid) == ERROR_SUCCESS)
4596
+ {
4597
+ isAzure = FALSE ;
4598
+ // Get the Graphic Adapter name
4599
+ if (GetValue (hKeyUserSid, AZUREAD_PROVIDERNAME_VALUE, csDomainAz) == ERROR_SUCCESS && csDomainAz == " AzureAD" )
4600
+ {
4601
+ isAzure = TRUE ;
4602
+ csDomain = csDomainAz;
4603
+ AddLog (_T (" \t\t <Connected to : %s>\n " ), csDomainAz);
4604
+ }
4605
+ else
4606
+ {
4607
+ AddLog (_T (" \t Failed in call to <RegQueryValueEx> function for HKLM\\ %s\\ %s !\n " ),
4608
+ csSubKey, AZUREAD_PROVIDERNAME_VALUE);
4609
+ csDomainAz = NOT_AVAILABLE;
4610
+ }
4611
+ // Get the Graphic Adapter name
4612
+ if (GetValue (hKeyUserSid, AZUREAD_DISPLAYNAME_VALUE, csDomainAz) == ERROR_SUCCESS && isAzure)
4613
+ {
4614
+ int nTokenPos = 0 ;
4615
+ CString strToken = csDomainAz.Tokenize (_T (" @" ), nTokenPos);
4616
+ CString csDomainName = NOT_AVAILABLE;
4617
+ while (!strToken.IsEmpty ())
4618
+ {
4619
+ csDomainName = strToken;
4620
+ strToken = csDomainAz.Tokenize (_T (" @" ), nTokenPos);
4621
+ }
4622
+
4623
+ if (csDomainName != NOT_AVAILABLE) {
4624
+ AddLog (_T (" \t\t <Domain : %s>\n " ), csDomainName);
4625
+ csDomain = csDomain + CString (" (" ) + csDomainName + CString (" )" );
4626
+ }
4627
+ }
4628
+ else
4629
+ {
4630
+ AddLog (_T (" \t Failed in call to <RegQueryValueEx> function for HKLM\\ %s\\ %s !\n " ),
4631
+ csSubKey, AZUREAD_DISPLAYNAME_VALUE);
4632
+ csDomainAz = NOT_AVAILABLE;
4633
+ }
4634
+ } // if RegOpenKey Object Key
4635
+ else
4636
+ AddLog (_T (" \t Failed in call to <RegOpenKeyEx> for HKLM\\ %s !\n " ),
4637
+ csSubKey);
4638
+
4639
+ dwIndexUser++;
4640
+ dwLength = 255 ;
4641
+ RegCloseKey (hKeyUserSid);
4642
+ }
4643
+ RegCloseKey (hKeyProperty);
4644
+ } // if RegOpenKey Object Key
4645
+ else
4646
+ AddLog (_T (" \t Failed in call to <RegOpenKeyEx> for HKLM\\ %s !\n " ),
4647
+ csSubKey);
4648
+ dwIndexGroup++;
4649
+ dwLength = 255 ;
4650
+ } // while RegEnumKey Group
4651
+ RegCloseKey (hKeyGroup);
4652
+ if (dwIndexGroup == 0 )
4653
+ // No key found
4654
+ AddLog (_T (" \t Failed in call to <RegEnumKeyEx> function to find subkey of HKLM\\ %s.\n " ),
4655
+ csSubKey);
4656
+ } // if RegOpenKey Group Key
4657
+ else
4658
+ AddLog (_T (" \t Failed in call to <RegOpenKeyEx> for HKLM\\ %s !\n " ),
4659
+ csSubKey);
4660
+ dwIndexEnum++;
4661
+ dwLength = 255 ;
4662
+ } // while RegEnumKey Enum
4663
+ RegCloseKey (hKeyEnum);
4664
+ if (dwIndexEnum == 0 )
4665
+ {
4666
+ // No key found
4667
+ AddLog (_T (" \t Failed in call to <RegEnumKeyEx> function to find subkey of HKLM\\ %s.\n " ),
4668
+ AZUREAD_KEY);
4669
+ return FALSE ;
4670
+ }
4671
+ AddLog (_T (" \t OK (%u objects).\n " ), uIndex);
4672
+ return TRUE ;
4673
+ } // if RegOpenKey enum Key
4674
+ AddLog (_T (" \t Failed in call to <RegOpenKeyEx> function for HKLM\\ %s !\n " ), AZUREAD_KEY);
4675
+ return FALSE ;
4538
4676
}
0 commit comments