How programattically use RegAsm.exe in Visual Basic 2013 I would like to write a Console program to automatically register COM dlls. The batch file I am using contains the following line of code. I really dislike the hard coding of paths to get to regasm, when you install a new.Net or run on a machine with a different version, you need to ensure you find a version of regasm. Here's a solution to find the regasm.exe from the most current.Net installed regasm. Within a bat file.
![Use Regasm From .bat Use Regasm From .bat](http://www.iwasdot.com/wp-content/uploads/2014/10/img_543e9dbc5d71a.png)
ProblemEver get this error when trying to register a.Net DLL as an ActiveX component using RegAsm.exe?“failed to load MyAssembly.dll because it is not a valid.net assembly”I’ll bet you’re using a version of.Net higher than 2.0, aren’t you? Turns out, each version of.Net you have installed has it’s own, version specific version of RegAsm.exe and when you run the RegAsm.exe command for your.Net 4.0 or so DLL, it’s running the.Net 2.0 version of RegAsm.exe.
Windows Registry ForensicsWhy make an ActiveX control if you’re using.Net? Sometimes you just have to for many reasons which are outside the scope of this article. SolutionGARDThere are a couple of ways to resolve this. Specify Specific VersionIf you want to specifically state which version to run, make a batch file for each version and name the batch file appropriately, and have that batch file have the hard path to the right RegAsm.exe.
For example, for the.Net 4.0 version of RegAsm, I created a batch file called RegAsm40.bat and put it in the same folder with the RegAsm.exe file for.Net 4.0 here:C:WindowsMicrosoft.NETFrameworkv4.0.30319The contents of my RegAsm40.bat file looks like this:C:WindowsMicrosoft.NETFrameworkv4.0.30319regasm.exe%1%2Now, from any Visual Studio command prompt (regardless of what folder I’m in), I type RegAsm40 (plus my parameters) and it’ll run it. Override default versionIf, on the other hand, you want to continue using the command RegAsm, you can create a batch file named RegAsm.bat and put it in each of the framework folders. All copies of those batch files should run the same, explicit version of RegAsm.exe you want.Unfortunately, you can’t simply rename the RegAsm.exe files without messing around with security settings. But that’s an option too which I’m not getting into here.See these images?You’ll find an actual working versions of them at the top and bottom of this article.
Please click the appropriate buttons in it to let your friends know about this article.Check back later for updates too! Search for: Search Recent Posts.Recent Comments.
on. on. on. on. onArchives.Categories.Meta.
TipIf you want to start multiple executable files, keep in mind that the batch file opens each of the files almost immediately. If you want some delay, consider using the or.If the file path contains a space within a folder name, you need to enclose that folder name in double quotes. For example, if you had Google Chrome installed on your computer and wanted to start the Chrome browser through a batch file, you could use the command below.START C:'Program Files (x86)'GoogleChromeApplicationchrome.exeThe Program Files (x86) folder name includes spaces in it. Enclosing the folder name in double quotes tells Windows the spaces are part of the folder name.
Can I control a program using a batch file once its been started?No. A batch file can only execute or start another program. Once it is started, it cannot perform additional functions within that program.