Share via

Moniker Strings in Visual Basic and VBScript

In Visual Basic or VBScript, objects can be created using the GetObject function combined with a moniker string. The following two examples show the difference between using a moniker string and not using a moniker string. The first example uses monikers as a concise alternative to the second example.

' First example
Set Service = GetObject("WinMgmts: _

' Second example
Set Locator = CreateObject("WbemScripting.SWbemLocator")
Set Service = Locator.ConnectServer       
service.Security_.ImpersonationLevel _
    = wbemImpersonationLevelImpersonate  
Set objinstance = Service.Get("Win32_Service=""ALERTER""")