我当前正在尝试在自动化软件上禁用Internet Explorer增强的安全配置,以在Windows 2019服务器上打开网站。
我能够运行Powershell脚本,该脚本使用与从C#应用程序运行它相同的命令从CMD手动和从CMD上编辑服务器上的注册表。
从C#运行Powershell脚本时,我得到了原本应该接收的输出,但是注册表没有更改。我怀疑这与执行政策有关。
C#
static void DownloadInstaller()
{
ProcessStartInfo info = new ProcessStartInfo();
info.WorkingDirectory = Directory.getcurrentDirectory();
info.FileName = "CMD.exe";
info.Arguments = "/c powershell -NoProfile -ExecutionPolicy ByPass -File .\\runIE.ps1";
info.UseShellExecute = true;
info.Verb = "runas";
Process.Start(info);
}
这是我正在运行的Powershell脚本
function Disable-InternetExplorerESC {
$AdminKey = "HKLM:\SOFTWARE\microsoft\active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"
$UserKey = "HKLM:\SOFTWARE\microsoft\active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}"
Set-ItemProperty -Path $AdminKey -Name "IsInstalled" -Value 0 -Force
Set-ItemProperty -Path $UserKey -Name "IsInstalled" -Value 0 -Force
Stop-Process -Name Explorer -Force -Erroraction Continue
Write-Host "IE Enhanced Security Configuration (ESC) has been disabled."
}
Disable-InternetExplorerESC
如果我的C#程序中有办法做到这一点,我希望获得一些帮助。