ฉันประสบปัญหานี้ซึ่งฉันไม่สามารถเรียกแอตทริบิวต์ AD ผ่าน DirectoryEntry
ได้ ฉันสามารถรับมันผ่าน DirectorySearcher
แต่ฉันไม่สามารถรับหรือตั้งค่าผ่าน DirectoryEntry
ได้
คุณลักษณะที่ต้องการคือ ms-Mcs-AdmPwdExpirationTime
ซึ่งมี NT TimeStamp ฉันได้อ่านและเขียนลงในคุณลักษณะนี้แล้ว
DirectoryEntry
ข้อผิดพลาด C# ในคอนโซล
ข้อผิดพลาด HRESULT E_FAIL ได้รับการส่งคืนจากการเรียกไปยังคอมโพเนนต์ COM
ฉันได้ลองใช้สิ่งต่อไปนี้แล้ว แต่ยังไม่สามารถเรียกข้อมูลแอตทริบิวต์ได้
RefreshCache (string[] propertyNames);
แก้ไข:
ComputerPrincipal comp = ComputerPrincipal.FindByIdentity(ctx, MachineName);
DirectoryEntry de = (DirectoryEntry)comp.GetUnderlyingObject();
if (de.Properties.Contains("ms-Mcs-AdmPwd") == true)
{
string Password = (String)de.Properties["ms-Mcs-AdmPwd"][0];
Password_Input.Text = Password;
DateTime NTTime = DateTime.FromFileTime(ConvertLargeIntegerToLong(de.Properties["ms-Mcs-AdmPwdExpirationTime"].Value));
PasswordExpiry_Value.Text = NTTime.ToString("dd/MM/yyyy hh:mm:ss");
Console.WriteLine();
}
else
{
Password_Input.Text = "Password not set by LAPS";
}
// down the bottom of the .cs
private static long ConvertLargeIntegerToLong(object largeInteger)
{
var type = largeInteger.GetType();
var highPart = Convert.ToInt32(type.InvokeMember("HighPart", BindingFlags.GetProperty, null, largeInteger, null));
var lowPart = Convert.ToInt32(type.InvokeMember("LowPart", BindingFlags.GetProperty, null, largeInteger, null));
return (long)highPart << 32 | (uint)lowPart;
}