Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell v2::加载COM互操作DLL_Powershell_Powershell 2.0 - Fatal编程技术网

Powershell v2::加载COM互操作DLL

Powershell v2::加载COM互操作DLL,powershell,powershell-2.0,Powershell,Powershell 2.0,我的系统上有这个数据链接DLL-Interop.MSDASC.DLL我正试图像这样从Powershell加载它- [Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") | out-null 但是,我得到了以下错误- Exception calling "LoadFile" with "1" argument(s): "Could not load file or assembly 'Interop.MSDASC.dll' or one

我的系统上有这个数据链接DLL-Interop.MSDASC.DLL我正试图像这样从Powershell加载它-

[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") | out-null
但是,我得到了以下错误-

Exception calling "LoadFile" with "1" argument(s): "Could not load file or assembly 'Interop.MSDASC.dll' or one of its dependencies.  is not a 
valid Win32 application. (Exception from HRESULT: 0x800700C1)"
At line:1 char:32
+ [Reflection.Assembly]::LoadFile <<<< ("C:\Interop.MSDASC.dll") | out-null
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
使用“1”参数调用“LoadFile”时出现异常:“无法加载文件或程序集'Interop.MSDASC.dll'或其依赖项之一。不是
有效的Win32应用程序。(HRESULT的异常:0x800700C1)
第1行字符:32

+[Reflection.Assembly]::LoadFile我刚刚从中下载了它,并以您使用的相同方式加载了程序集,没有问题:

 [System.Reflection.Assembly]::LoadFile( "c:\Program Files\DataDictionaryCreator\Interop.MSDASC.dll")

GAC    Version        Location
---    -------        --------
False  v2.0.50727     c:\Program Files\DataDictionaryCreator\Interop.MSDASC.dll
你可能在x64操作系统上吗?
如果是,请阅读此处

这是一个32位COM对象,因此必须从PowerShell的32位实例加载它。要在64位版本的Windows上执行此操作,您可以在此文件夹中执行powershell.exe或powershell_ISE.exe: %SYSTEMROOT%\SysWow64\windowspowershell\v1.0

这是完整的代码:

[Reflection.Assembly]::LoadFile("C:\Interop.MSDASC.dll") 
$dataLinkInstance = new-object MSDASC.DataLinksClass
$dataLinkInstance.WriteStringToStorage("C:\\FrmPowershell.udl", "Provider=SQLOLEDB.1;", 2)

你是在说Powershell吗?是的。已在powershell中加载程序集对我来说没问题!我使用的是Windows7x86.Cool。但是,我没有这样的.Net应用程序。我只是直接尝试加载互操作DLL。我使用的是64位Windows 7。我还是不明白为什么?有线索吗?我将尝试从Framework 32文件夹执行regasm,以便在WOW6432node下注册它?您是否尝试过在x86中使用powershell.exe?路径是:“%SYSTEMROOT%\SysWow64\windowspowershell\v1.0\\powershell.exe”好建议。我明天会试试,然后更新。但是,当脚本将使用POwershell API从C#app调用时,我们如何在生产中处理此类场景?请解释您做了什么以及为什么这么做。在这一点上,这个答案对于帮助OP了解该做什么没有指导意义。
$comInterOp = "C\Temp\Interop.YourAssembly.dll"
[System.Reflection.Assembly]::LoadFile($comInterOp)
$yourClassObj = new-object YourAssembly.YourClassNameClass
$yourResult = $yourClassObj.YourMethod()