var path = new ManagementPath();
path.NamespacePath = "\\ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption"; path.ClassName = "Win32_EncryptableVolume";
var scope = new ManagementScope(path, new ConnectionOptions() { Impersonation = ImpersonationLevel.Impersonate });
var management = new ManagementClass(scope, path, new ObjectGetOptions());
foreach (ManagementObject vol in management.GetInstances())
{
Console.WriteLine("----" + vol["DriveLetter"]);
switch ((uint)vol["ProtectionStatus"])
{
case 0:
Console.WriteLine("not protected by bitlocker");
break;
case 1:
Console.WriteLine("unlocked");
break;
case 2:
Console.WriteLine("locked");
break;
}
if ((uint)vol["ProtectionStatus"] == 2)
{
Console.WriteLine("unlock this driver ...");
vol.InvokeMethod("UnlockWithPassphrase", new object[] { "here your pwd" });
Console.WriteLine("unlock done.");
}
}
Lưu ý: điều này chỉ hoạt động nếu bạn chạy Visual Studio với tư cách quản trị viên.
Nếu bạn có thông tin đăng nhập (tên người dùng và mật khẩu), bạn có một vấn đề khác. –
Bản sao của http://stackoverflow.com/questions/5764174/unlock-local-computer-using-net –
Đề xuất của tôi không phải là khóa máy trạm. Ý tôi là, nếu bạn muốn nó mở khóa sau đó chỉ cần kiềm chế khóa nó. –