Use Regasm From .bat

Posted on

A quote from the documentation:. Source: Microsoft, Windows XP Professional Product Documentation,Using multiple commands and conditional processing symbolsYou can run multiple commands from a single command line or script using conditional processing symbols. When you run multiple commands with conditional processing symbols, the commands to the right of the conditional processing symbol act based upon the results of the command to the left of the conditional processing symbol.For example, you might want to run a command only if the previous command fails. Or, you might want to run a command only if the previous command is successful.You can use the special characters listed in the following table to pass multiple commands.&. How do i delete duplicate holidays in outlook 2016. command1 & command2Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.&&. command1 && command2Use to run the command following && only if the command preceding the symbol is successful.

Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully. command1 command2Use to run the command following only if the command preceding fails. Cmd.exe runs the first command, and then runs the second command only if the first command did not complete successfully (receives an error code greater than zero).( ).

(command1 & command2)Use to group or nest multiple commands.; or, command1 parameter1;parameter2Use to separate command parameters. So, I was trying to enable the specific task of running RegAsm (register assembly) from a context menu. The issue I had was that the result would flash up and go away before I could read it.

So I tried piping to Pause, which does not work when the command fails (as mentioned here and here ). So I tried cmd /k but that leaves the window open for more commands (I just want to read the result).

So I added a pause followed by exit to the chain, resulting in the following:cmd /k C:WindowsMicrosoft.NETFrameworkv4.0.30319regasm.exe '%1' /codebase '%1' & pause & exitThis works like a charm - RegAsm runs on the file and shows its results, then a 'Press any key to continue.' Prompt is shown, then the command prompt window closes when a key is pressed.P.S. For others who might be interested, you can use the following.reg file entries to add a dllfile association to.dll files and then a RegAsm command extension to that (notice the escaped quotes and backslashes): HKEYCLASSESROOT.dll'Content Type'='application/x-msdownload'@='dllfile'HKEYCLASSESROOTdllfile@='Application Extension'HKEYCLASSESROOTdllfileShellRegAsm@='Register Assembly'HKEYCLASSESROOTdllfileShellRegAsmcommand@='cmd /k C:WindowsMicrosoft.NETFrameworkv4.0.30319regasm.exe '%1' /codebase '%1' & pause & exit'Now I have a nice right-click menu to register an assembly.

.bat

Like this on all Microsoft OSes since 2000, and still good today: dir & echo fooIf you want the second command to execute only if the first exited successfully: dir && echo fooThe single ampersand (&) syntax to execute multiple commands on one line goes back to Windows XP, Windows 2000, and some earlier NT versions.

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.

Use Regasm From .batUse Regasm From .bat

Use Regasm From .bat Pdf

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!

Use Regasm From .bat Time

Categories, Tags,.