简体   繁体   中英

Registering a .NET DLL with Regasm using Powershell fails

With visual studio 2012 I created a DLL file in C# which can be used in Access 2013 by referencing it. This all works fine. I Created the DLL and registered it with CMD doing: RegAsm.exe -tlb -codebase C:\\MyFolderX\\MyDLL.dll

This all works fine, but because the DLL needs to be registered at multiple computers I wanted to do this with 1 click instead of doing it manually at each user computer.

Because users already use a BATCH file to launch the Access frontend application (which uses the DLL) I thought it would be wise to register it once when they use the BATCH startup. So to do this this I added the following in my BATCH script:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
RegAsm.exe -tlb -codebase C:\MyFolderX\MyDLL.dll

This sadly doesn't work because it has to be done in admin mode and checking the checkbox run as administrator just jumps through my BATCH code without doing anything for some reason.

So I though, why not use a Powershell script to do the same and launch that from my batch script.

To do this I created the following script:

#Register the assembly
$RegAsm = 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe -codebase -tlb'
$Assembly = 'C:\MyFolderX\MyDLL.dll'

Start-Process $RegAsm $Assembly

pause

This however keeps giving the error:

Start-Process : This command cannot be run due to the error: The system cannot find the file specified. At C:\users\me\Desktop\RegisterMyDLL.pst1

+Start-Process $RegAsm $Assembly

InvalidOperation: (:) Start-Process
FullyQualifiedErrorId : InvalidOperationException, Microsoft.Powershell.Commands.StartProcessCommand

I double checked the location of the DLL and it it just there.. Anyone have a clue what I am doing wrong? Perhaps some syntax error or quote to much? Already tried to escape my backslashes but this didn't had any effect.

Or perhaps there is an better way to achieve easy DLL registering at multiple users?

这样行吗?

 ."C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe" -codebase -tlb $Assembly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM