C#带有PowerShell自动化命令限制的Windows窗体应用程序



我正在尝试创建一个应用程序,以编程方式设置bitlocker PIN。

该应用程序与PowerShell命令一样工作,但不幸的是,我无法执行它。

执行时出现以下错误:

"应用程序试图执行安全策略不允许的操作。若要授予此应用程序所需的权限,请与系统管理员联系或使用Microsoft。网络配置工具";

private void Submit_Click(object sender, EventArgs e)
{
if (PIN.Text.Length < 20)
{
MessageBox.Show("Passwords must be at least 20 characters long.");
return;
}
else if (PIN2.Text != PIN.Text)
{
MessageBox.Show("Password & Confirmation are not identical, Please ensure that both Passwords are the same");
return;
}
else
{
PowerShell ps = PowerShell.Create();
ps.AddCommand("$PIN = "" + PIN.Text + "" | ConvertTo-SecureString -AsPlainText -Force; Enable-BitLocker -MountPoint "C:" -PIN $PIN -TPMAndPinProtector -SkipHardwareTest");
ps.Invoke();
MessageBox.Show("Your Pre-Boot PIN has now been Setup - Please reboot after 30 Minutes and login with your PIN");
Application.Exit();

我已经设置了程序集:SecurityRules(SecurityRuleSet.Level1(,但问题仍然存在。

这是一个需要修改的GPO吗?或者我可以在应用程序中绕过吗?

您是否尝试制作一个实际的PowerShell脚本文件,然后运行该文件?

看看这个

最新更新