Which .NET Classes Can Be Used from Scripts?

In general, if the documentation definition for a class includes a ComVisibleAttribute that's set to True, you can try creating it within a script, but some experimentation is necessary.

Alex Angelopoulos

March 4, 2008

1 Min Read
ITPro Today logo in a gray background | ITPro Today

There's no simple answer to the question of which .NET components can be used from scripts. MSDN does have some documentation about how to write .NET components that can be used by COM applications—but "Exposing .NET Framework Components to COM" (http://msdn2.microsoft.com/en-us/library/zsfww439.aspx) is more useful to programmers than to administrators. Fortunately, there are some simple ways to try particular .NET classes and some rules of thumb to determine if they're usable from scripts.

If you're not familiar with .NET classes at all, you can begin by browsing through ".NET Framework Class Library" (http://msdn2.microsoft.com/en-us/library/ms229335.aspx). That page provides links to .NET namespaces, each of which contains one or more classes. If the class documentation's definition includes a ComVisibleAttribute that's set to True, you can try creating it within a script by using CreateObject. Use the fully qualified .NET class name as the programmatic identifier with CreateObject.

Let's look at a quick example. The Queue class documented at http://msdn2.microsoft.com/en-us/library/system.collections.queue.aspx is COM-visible. You can tell this because the declaration shown in Visual Basic syntax includes the attribute . Queue's fully qualified .NET class name is just the namespace location (System.Collections) with a namespacing dot (.) followed by the class name Queue, so you can create an instance of it in VBScript like this:

set sb = CreateObject("System.Collections.Queue")

You'll need to experiment with particular .NET classes to determine whether they're useful. Be aware that if the documentation says that a class is static, you can't use it, and if a class method is described as overloaded, you can't easily use that method, even if you can create the class.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like