Using a 32bit COM object in a 64bit environment

人走茶凉 提交于 2019-12-13 14:06:06

问题


I'm using powershell 3 on Win7/64bit . I am trying to use .net of excel (32bit) with this command : [microsoft.office.interop.excel.xlfileformat] And I got this error: unable to find type microsoft.office.interop.excel.xlfileformat: make sure that the assembly containing this type is loaded. I didn't have this error before when I used Win7/32bit. Maybe someone know how to fix that?


回答1:


You need to load the Excel interop assembly like so:

Add-Type -AssemblyName Microsoft.Office.Interop.Excel

If you need to use types defined in the Excel interop assembly, you have to load that assembly into PowerShell before you can reference types defined in it. You're using an enumeration (xlFileFormat) so PowerShell needs the definition of that type.




回答2:


Had a bit of a similar problem when trying to run the Redemption.dll in PowerShell 64 bit for Outlook 2010 32 bit. This is how I solved it:

regsvr32.exe 'C:\path\Redemption.dll'
regsvr32.exe 'C:\path\Redemption64.dll'

$Job = Start-Job -ScriptBlock {
    $routlook = New-Object -COM Redemption.RDOSession
    $routlook
    } -RunAs32

Wait-Job -Job $Job
Receive-Job -Job $Job

Apparently Start-Job has a switch to run a ScriptBlock in 32 bit mode. This works just great for what I need it!



来源:https://stackoverflow.com/questions/17681958/using-a-32bit-com-object-in-a-64bit-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!