我正在寻找使用vbscript从活动目录中恢复bitlocker密码的链接,但我想使用我的c#程序来实现这一点。
我已经找到了一些相关信息,但到目前为止还没有任何成功。任何人都可以帮助并纠正代码,或指出我解决这个问题的方向吗?
这是我发现并测试的最新代码,但它不起作用
class BitlockerModel
{
public string RecoveryGuid { get; set; }
public string RecoveryPassword { get; set; }
public string Date { get; set; }
public string Time { get; set; }
public BitlockerModel()
{
RecoveryGuid = string.Empty;
RecoveryPassword = string.Empty;
Date = string.Empty;
Time = string.Empty;
}
}
private void btnBitlockerSearch_Click(object sender, EventArgs e)
{
try
{
var computerName = txtBitlockerSearch.Text;
if ((string.IsNullOrEmpty(computerName)))
{
MessageBox.Show(@"Computername can't be empty");
return;
}
var bitlockerObject = new BitlockerLookup();
var result = bitlockerObject.GetBitlockerInfo(computerName).ToList();
foreach (var items in result)
{
lsBitlockerInformation.Items.Add(string.Format("Date: {0}", items.Date));
lsBitlockerInformation.Items.Add(string.Format("Time: {0}", items.Time));
lsBitlockerInformation.Items.Add(string.Format("RecoveryGUID: {0}", items.RecoveryGuid));
lsBitlockerInformation.Items.Add(string.Format("Recovery Password: {0}", items.RecoveryPassword));
lsBitlockerInformation.Items.Add(Environment.NewLine);
}
}
catch
{
MessageBox.Show(@"Enter a Valid ComputerName");
}
}
internal class BitlockerLookup
{
public List<BitlockerModel> GetBitlockerInfo(string computerName)
{
var returnRecoveryInfo = LookupBitlockerRecoveryInfor(computerName);
return returnRecoveryInfo;
}
private static List<BitlockerModel> LookupBitlockerRecoveryInfor(string computerName)
{
var bitlockerModelList = new List<BitlockerModel>();
var dsSearcher = new DirectorySearcher
{
Filter = String.Format("(&(objectCategory=Computer)(cn={0}))", computerName)
};
try
{
var srResult = dsSearcher.FindOne();
if (srResult == null)
{
MessageBox.Show(@"Failed to find the computer object.", @"Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
else
{
var objValue = Marshal.BindToMoniker(srResult.GetDirectoryEntry().Path.Replace("GC://", "LDAP://"));
var tType = objValue.GetType();
tType.InvokeMember("Filter",
System.Reflection.BindingFlags.SetProperty | System.Reflection.BindingFlags.Public, null,
objValue, new Object[] {"msFVE-RecoveryInformation"});
foreach (var obj in (IEnumerable) objValue)
{
var tempList = new BitlockerModel();
var gRecoveryGuid =
new Guid(
(Byte[])
obj.GetType()
.InvokeMember("msFVE-RecoveryGuid",
System.Reflection.BindingFlags.GetProperty |
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null));
var name =
obj.GetType()
.InvokeMember("name",
System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null)
.ToString();
var date = name.Substring(3, name.IndexOf("T", System.StringComparison.Ordinal) - 3);
var objDate = Convert.ToDateTime(date);
date = string.Format("{0:dddd, MMMM d, yyyy}", objDate);
var time = name.Substring(name.IndexOf("T", System.StringComparison.Ordinal) + 1,
name.IndexOf("{", System.StringComparison.Ordinal) - 20);
var objTime = DateTime.Parse(time).ToString("h:mm:ss tt");
time = objTime;
tempList.Time = time;
tempList.Date = date;
tempList.RecoveryGuid = "{" + gRecoveryGuid.ToString().ToUpper() + "}";
tempList.RecoveryPassword =
obj.GetType()
.InvokeMember("msFVE-RecoveryPassword",
System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null)
.ToString();
bitlockerModelList.Add(tempList);
}
return bitlockerModelList;
}
}
catch
{
MessageBox.Show(@"Error, you must enter a computer name");
return null;
}
return new List<BitlockerModel>();
}
}
答案 0 :(得分:0)
想出来,开始代码工作正常,虽然我必须构建一个模型来保存响应并使用管理员帐户运行应用程序