With the Component Object Model (COM) offers Microsoft a standard system wide interface to get properties or to use methods. COM is used a lot in the Windows environment. With the dotNET Framework and Core is it also possible to use this kind of interface. But here it is necessary to build an interoperability library first. To do this, Microsoft offers a tool called TlbImp (TypeLibrary Importer). You can find this tool in the Windows Software Development Toolkit (SDK). Download and install the SDK, now you can find TlbImp.exe at the path:
<YourInstallPath>\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\
.
The tool itself is very easy to use, e.g.
tlbimp.exe wshom.ocx /out:wshom.dll
to create an interoperability library for the Windows Scripting Host (Wsh). Copy the wshom.dll into your automation workflow project directory, and now you can use the Wsh seamlessly in your Invoke Code activity. In the following example I request the UserName property from the Network class.
System.Reflection.Assembly Wsh = System.Reflection.Assembly.LoadFrom(@"wshom.dll");
System.Object WshNet = Wsh.CreateInstance("wshom.WshNetworkClass");
System.Reflection.PropertyInfo UserName = WshNet.GetType().GetProperty("UserName");
string Result = UserName.GetValue(WshNet).ToString();
System.Console.WriteLine(Result);
Also you can call methods, but here it is necessary to use GetMethod instead GetProperty and Invoke instead GetValue.
A very positive side effect of this approach is also the possibility to bypass the LateBinding.
Conclusion
With the possiblity of the type library importing we can use COM libraries very easily in the context of our UiPath automation workflows. This approach works with the compatibility modes dotNET 4.61 (Windows - Legacy) and dotNET 5.0 (Windows). For each COM library an interoperability library can be build on this way, e.g. if one should be missing. Also the interoperability libraries can be packaged into NuGet packages and used on that way.