使用 PowerShell 脚本安装 COM + 组件的问题
Issues in installing COM + Component using PowerShell script
我正在尝试使用 powershell 安装 COM + 组件。但我收到以下错误。
Unable to find type [some.dll]. Make sure that the assembly that contains this
type is loaded.
+ $comAdmin.InstallComponent("test", [some.dll]);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (COMITSServer.dll:TypeName) [], Runtime
Exception
+ FullyQualifiedErrorId : TypeNotFound
这是我的 powershell 脚本:
安装 COM + 组件
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog;
$comAdmin.InstallComponent("some", [some.dll]);
#if an exception occurs in installing COM+ then display the message below
if (!$?)
{
Write-Host "Unable to Install the COM+ Component. Aborting..."
exit -1
}
我的powershell版本是4.0
有人可以帮我解决这个问题吗?
谢谢。
PowerShell 中的方括号表示一种类型,例如 [string]
或 [int32]
或 [System.Array]
或 [System.Math]
。错误消息是抱怨,因为您告诉 PowerShell COMITSServer.dll 是已注册和加载的数据类型。
此外,COMAdminCatalog
的 InstallComponent
方法在我看来有 四个 个参数,而不是两个。看定义应该可以确认,但不知道v2.0是否支持这样:
PS U:\> $comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
PS U:\> $comAdmin | gm | where { $_.Name -eq 'InstallComponent' }
TypeName: System.__ComObject#{790c6e0b-9194-4cc9-9426-a48a63185696}
Name MemberType Definition
---- ---------- ----------
InstallComponent Method void InstallComponent (string, string, string, string)
因此,我会试试这个:
$comAdmin.InstallComponent("ITSServerOO2", "COMITSServer.dll", "", "");
这似乎是 VB 代码 here 调用相同方法的方式:
' Open a session with the catalog.
' Instantiate a COMAdminCatalog object.
Dim objCatalog As COMAdminCatalog
Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog")
[...]
' Install components into the application.
' Use the InstallComponent method on COMAdminCatalog.
' In this case, the last two parameters are passed as empty strings.
objCatalog.InstallComponent "MyHomeZoo","MyZoo.DLL","",""
Here 是该函数的 class 定义,我相信,尽管我对 COM+ 不够熟悉,不知道 COMAdminCatalog 和 ICOMAdminCatalog 是否相同。
这是对有关 0x80110401 HRESULT 的问题的回答。 (顺便说一句,后续问题应该在 SO 上的新 post 中回答,而不是在现有问题的评论中回答)。这可以让其他人在遇到相同问题时找到答案。
ICOMAdminCatalog::InstallComponent 的文档。正如文档所解释的那样,第一个参数是 GUID,第二个是正在注册的 DLL。第三个参数(typelib)和第四个(proxy stub DLL)是可选的,可以指定为空字符串。
"test" 不是有效的 GUID。请注意,GUID 是一种独特的 .NET 类型 (System.Guid
)。然而,文档要求将转换为 System.String
的 BSTR。要获取字符串形式的新 GUID,请使用:[Guid]::NewGuid().toString()
。
请注意,COM+ 组件的 GUID 是 "well known" 值,由实现接口的 COM 服务器和使用 COM 服务器接口的客户端使用。所以通常你不想在注册 COM 服务器时生成一个新的 GUID,而是使用开发人员在开发 COM 服务器时创建的那个。但是,如果您不知道要使用的正确 GUID 是什么,那么生成一个新的 GUID 至少可以让您在开发脚本方面取得进展。
这可能会或可能不会解决导致 0x80110401 的问题,但它肯定会解决您迟早 运行 遇到的问题。
我正在尝试使用 powershell 安装 COM + 组件。但我收到以下错误。
Unable to find type [some.dll]. Make sure that the assembly that contains this
type is loaded.
+ $comAdmin.InstallComponent("test", [some.dll]);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (COMITSServer.dll:TypeName) [], Runtime
Exception
+ FullyQualifiedErrorId : TypeNotFound
这是我的 powershell 脚本:
安装 COM + 组件
$comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog;
$comAdmin.InstallComponent("some", [some.dll]);
#if an exception occurs in installing COM+ then display the message below
if (!$?)
{
Write-Host "Unable to Install the COM+ Component. Aborting..."
exit -1
}
我的powershell版本是4.0 有人可以帮我解决这个问题吗?
谢谢。
PowerShell 中的方括号表示一种类型,例如 [string]
或 [int32]
或 [System.Array]
或 [System.Math]
。错误消息是抱怨,因为您告诉 PowerShell COMITSServer.dll 是已注册和加载的数据类型。
此外,COMAdminCatalog
的 InstallComponent
方法在我看来有 四个 个参数,而不是两个。看定义应该可以确认,但不知道v2.0是否支持这样:
PS U:\> $comAdmin = New-Object -comobject COMAdmin.COMAdminCatalog
PS U:\> $comAdmin | gm | where { $_.Name -eq 'InstallComponent' }
TypeName: System.__ComObject#{790c6e0b-9194-4cc9-9426-a48a63185696}
Name MemberType Definition
---- ---------- ----------
InstallComponent Method void InstallComponent (string, string, string, string)
因此,我会试试这个:
$comAdmin.InstallComponent("ITSServerOO2", "COMITSServer.dll", "", "");
这似乎是 VB 代码 here 调用相同方法的方式:
' Open a session with the catalog.
' Instantiate a COMAdminCatalog object.
Dim objCatalog As COMAdminCatalog
Set objCatalog = CreateObject("COMAdmin.COMAdminCatalog")
[...]
' Install components into the application.
' Use the InstallComponent method on COMAdminCatalog.
' In this case, the last two parameters are passed as empty strings.
objCatalog.InstallComponent "MyHomeZoo","MyZoo.DLL","",""
Here 是该函数的 class 定义,我相信,尽管我对 COM+ 不够熟悉,不知道 COMAdminCatalog 和 ICOMAdminCatalog 是否相同。
这是对有关 0x80110401 HRESULT 的问题的回答。 (顺便说一句,后续问题应该在 SO 上的新 post 中回答,而不是在现有问题的评论中回答)。这可以让其他人在遇到相同问题时找到答案。
ICOMAdminCatalog::InstallComponent 的文档。正如文档所解释的那样,第一个参数是 GUID,第二个是正在注册的 DLL。第三个参数(typelib)和第四个(proxy stub DLL)是可选的,可以指定为空字符串。
"test" 不是有效的 GUID。请注意,GUID 是一种独特的 .NET 类型 (System.Guid
)。然而,文档要求将转换为 System.String
的 BSTR。要获取字符串形式的新 GUID,请使用:[Guid]::NewGuid().toString()
。
请注意,COM+ 组件的 GUID 是 "well known" 值,由实现接口的 COM 服务器和使用 COM 服务器接口的客户端使用。所以通常你不想在注册 COM 服务器时生成一个新的 GUID,而是使用开发人员在开发 COM 服务器时创建的那个。但是,如果您不知道要使用的正确 GUID 是什么,那么生成一个新的 GUID 至少可以让您在开发脚本方面取得进展。
这可能会或可能不会解决导致 0x80110401 的问题,但它肯定会解决您迟早 运行 遇到的问题。