【问题标题】:Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} failed检索具有 CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} 的组件的 COM 类工厂失败
【发布时间】:2015-10-16 01:17:32
【问题描述】:

我正在创建停止 IIS 默认网站的应用程序。我使用 PowerShell 脚本来停止网站,因为该脚本是从我的网站执行的。

这是我的脚本:

Import-Module C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration
Stop-Website 'Default Web Site'
my copy code
Start-Website 'Default Web Site'

这是我的 C# 代码:

PowerShell _PowerShell = PowerShell.Create();

Runspace rs = RunspaceFactory.CreateRunspace();
rs.Open();

_PowerShell.Runspace = rs;
_PowerShell.AddScript(@"Set-ExecutionPolicy RemoteSigned -scope LocalMachine").Invoke();
_PowerShell.AddScript(@"E:\DE.TEST\Power_Shell\Scripts\StopIISDefaultSite.ps1").Invoke();

if (_PowerShell.HadErrors)
{
    Collection<ErrorRecord> errors = _PowerShell.Streams.Error.ReadAll();

    foreach (var item in errors)
    {
        Console.WriteLine(item.ToString());
    }
}

Console.ReadLine();

显示如下错误

由于以下错误,检索具有 CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6} 的组件的 COM 类工厂失败:80040154 未注册类(HRESULT 异常:0x80040154 (REGDB_E_CLASSNOTREG))。

【问题讨论】:

  • 我正在使用任何 CPU。我不是 powershell 的大师 :(
  • 我将其更改为 x86。仍然发生错误。
  • 显然某些东西没有在该机器上注册(即需要注册以便代码对其执行的 COM 组件)
  • @CodeCaster 好像反过来了,you need to target x64
  • 我们可以使用任何 CPU 来执行这个东西吗?

标签: c# asp.net powershell iis iis-8


【解决方案1】:

您需要检查运行 PS 代码的 PowerShell 实例是 32 位还是 64 位,并为该目标平台构建解决方案。 您可以使用以下方法进行检查:

if([IntPtr]::size -eq 8) { Write-Host 'x64' } else { Write-Host 'x86' }

Source

正如 cmets 设置中所指出的,如果您正在运行 64 位 PowerShell,则为 AnyCPU 构建您的解决方案并取消选中“首选 32 位”可以解决问题。

【讨论】:

  • 为任何未选中“首选 32 位”的 CPU 构建似乎对我有用(但我只在 64 位机器上测试过)。
【解决方案2】:

继@Jenish Zinzuvadiya 对 PowerShell 作为 x86/x64 运行的回答之后,在我的情况下,问题是我使用“打开命令行”插件从 Visual Studio 启动 PowerShell,该插件将 PowerShell 作为 x86 进程启动.

从“开始”菜单启动 PowerShell 是一个 x64 进程,这为我解决了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-14
    • 2012-02-17
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多