English 中文(简体)
Powerhell v2
原标题:Powershell v2 :: Load a COM Interop DLL

我的系统有这一数据链接,Interop.MSDASC.dll。 我正试图从像这样的大国身上装上同样的东西——

[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

我如何正确装载这件事?

最佳回答

This is a 32 bit COM object and therefore you must load it from a 32 bit instance of PowerShell. To do this on a 64 bit version of Windows you can execute powershell.exe or powershell_ISE.exe in this folder: %SYSTEMROOT%SysWow64windowspowershellv1.0

这是一部完整的法典:

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

http://datadictionary.codeplex.com/“rel=“nofollow”http://datadictionary.codeplex.com/。 以同样方式使用和装货组,没有问题:

 [System.Reflection.Assembly]::LoadFile( "c:Program FilesDataDictionaryCreatorInterop.MSDASC.dll")

GAC    Version        Location
---    -------        --------
False  v2.0.50727     c:Program FilesDataDictionaryCreatorInterop.MSDASC.dll

Are you maybe on a x64 operative system? if yes read here http://datadictionary.codeplex.com/workitem/28807

$comInterOp = "CTempInterop.YourAssembly.dll"
[System.Reflection.Assembly]::LoadFile($comInterOp)
$yourClassObj = new-object YourAssembly.YourClassNameClass
$yourResult = $yourClassObj.YourMethod()




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签