I’m lazy as any good admin should be. I don’t like having to search for information when I don’t have to. I especially don’t like searching for “that one EXE file I knew was here somewhere” or what syntax to use for that EXE file. This is why I create simple, little functions that may seem tedious and unnecessary at first. I create these functions to fit my brain. Whenever I need to do something I immediately think “What cmdlet would I look for?” and if it doesn’t exist I create it. Even if it’s to execute a 1-line EXE file.
Can I Use Entity/Use Codes in Sage 100 Sales Tax? You want to know if you can use entity use codes in Sage 100. Do we have to do anything with AvaTax if our license keys are changing in Sage 100? Create.bat file with this code: C: Windows Microsoft.NET Framework64 v4.0.30319 RegAsm.exe /codebase FULLPATHTODLLFILE Run this bat file as Administrator (Right-click - Run as Administrator, or run CMD line as admin and run it from there to see the results). Run the.bat “as Administrator”. Regsvr32 will be trying to create entries in the Windows registry, so it may need administrative privileges. On Windows 7, open an Administrator command prompt by going to the Start Menu, enter “cmd” in the search box and instead of pressing Enter, press Ctrl+Shift+Enter.
In this instance, I have the function called Register-File
. The only real thing this does is execute regsvr32.exe /s $SomeFile
and ensure $SomeFile
exists. It may sound foolish but I can never seem to remember the exact syntax plus I always seem to fat-finger the file somehow, watch it error and try again. All I have to do now is type Register-File with the file name and be done. Register-File
is a lot easier to remember that regsvr32.exe /s
, right?
STOP! Quit reading this article and start writing your own to attract more readers and learn how to get paid for them! In my latest eBook, Teach Me: How to Write How-to Technical Articles that Make Money, I uncover all of the tips and tricks I've learned over the years to create better articles to build a 50K user/month blog and generate over $200,000!
P.S. Another good way to prevent having to remember syntax is Powershell aliases. Perhaps I’ll leave that one for another post.
2 4 6 8 10 12 14 | <# A function that uses the utility regsvr32.exe utility to register a file The file path [CmdletBinding()] [ValidateScript({Test-Path-Path$_-PathType'Leaf'})] ) try{ $Result=Start-Process-FilePath'regsvr32.exe'-Args'/s <code>'$FilePath</code>'-Wait-NoNewWindow-PassThru}catch{Write-Error$_.Exception.Message$false}}} |
The Assembly Registration tool reads the metadata within an assembly and adds the necessary entries to the registry, which allows COM clients to create .NET Framework classes transparently. Once a class is registered, any COM client can use it as though the class were a COM class. The class is registered only once, when the assembly is installed. Instances of classes within the assembly cannot be created from COM until they are actually registered.
To run the tool, use the Developer Command Prompt for Visual Studio. For more information, see Command Prompts.
At the command prompt, type the following:
Parameter | Description |
---|---|
assemblyFile | The assembly to be registered with COM. |
Option | Description |
---|---|
/codebase | Creates a Codebase entry in the registry. The Codebase entry specifies the file path for an assembly that is not installed in the global assembly cache. You should not specify this option if you will subsequently install the assembly that you are registering into the global assembly cache. The assemblyFile argument that you specify with the /codebase option must be a strong-named assembly. |
/registered | Specifies that this tool will only refer to type libraries that have already been registered. |
/asmpath:directory | Specifies a directory containing assembly references. Must be used with the /regfile option. |
/nologo | Suppresses the Microsoft startup banner display. |
/regfile [:regFile] | Generates the specified .reg file for the assembly, which contains the needed registry entries. Specifying this option does not change the registry. You cannot use this option with the /u or /tlb options. |
/silent or /s | Suppresses the display of success messages. |
/tlb [:typeLibFile] | Generates a type library from the specified assembly containing definitions of the accessible types defined within the assembly. |
/unregister or /u | Unregisters the creatable classes found in assemblyFile. Omitting this option causes Regasm.exe to register the creatable classes in the assembly. |
/verbose | Specifies verbose mode; displays a list of any referenced assemblies for which a type library needs to be generated, when specified with the /tlb option. |
/? or /help | Displays command syntax and options for the tool. |
Note
The Regasm.exe command-line options are case insensitive. You only need to provide enough of the option to uniquely identify it. For example, /n is equivalent to /nologo and /t:outfile.tlb is equivalent to /tlb:outfile.tlb.
You can use the /regfile option to generate a .reg file that contains the registry entries instead of making the changes directly to the registry. You can update the registry on a computer by importing the .reg file with the Registry Editor tool (Regedit.exe). Note that the .reg file does not contain any registry updates that can be made by user-defined register functions. Note that the /regfile option only emits registry entries for managed classes. This option does not emit entries for TypeLibID
s or InterfaceID
s.
When you specify the /tlb option, Regasm.exe generates and registers a type library describing the types found in the assembly. Regasm.exe places the generated type libraries in the current working directory or the directory specified for the output file. Generating a type library for an assembly that references other assemblies may cause several type libraries to be generated at once. You can use the type library to provide type information to development tools like Visual Studio. You should not use the /tlb option if the assembly you are registering was produced by the Type Library Importer (Tlbimp.exe). You cannot export a type library from an assembly that was imported from a type library. Using the /tlb option has the same effect as using the Type Library Exporter (Tlbexp.exe) and Regasm.exe, with the exception that Tlbexp.exe does not register the type library it produces. If you use the /tlb option to registered a type library, you can use /tlb option with the /unregister option to unregistered the type library. Using the two options together will unregister the type library and interface entries, which can clean the registry considerably.
When you register an assembly for use by COM, Regasm.exe adds entries to the registry on the local computer. More specifically, it creates version-dependent registry keys that allow multiple versions of the same assembly to run side by side on a computer. The first time an assembly is registered, one top-level key is created for the assembly and a unique subkey is created for the specific version. Each time you register a new version of the assembly, Regasm.exe creates a subkey for the new version.
For example, consider a scenario where you register the managed component, myComp.dll, version 1.0.0.0 for use by COM. Later, you register myComp.dll, version 2.0.0.0. You determine that all COM client applications on the computer are using myComp.dll version 2.0.0.0 and you decide to unregister myComponent.dll version 1.0.0.0. This registry scheme allows you to unregister myComp.dll version 1.0.0.0 because only the version 1.0.0.0 subkey is removed.
After registering an assembly using Regasm.exe, you can install it in the global assembly cache so that it can be activated from any COM client. If the assembly is only going to be activated by a single application, you can place it in that application's directory.
The following command registers all public classes contained in myTest.dll
.
The following command generates the file myTest.reg
, which contains all the necessary registry entries. This command does not update the registry.
The following command registers all public classes contained in myTest.dll
, and generates and registers the type library myTest.tlb
, which contains definitions of all the public types defined in myTest.dll
.