ClearScript Library
ClearScript Library
ClearScript Library Reference
Microsoft.ClearScript
ExtendedHostFunctions Class
ExtendedHostFunctions Methods
arrType<T> Method
comType Method
lib Method
newComObj Method
type Method
typeLibEnums<T> Method

# ExtendedHostFunctionsnewComObj Method

Creates a COM/ActiveX object of the specified type.
Namespace: Microsoft.ClearScript
Assembly: ClearScript.Core (in ClearScript.Core.dll) Version: 7.5.0
Syntax
C#
VB
C++
F#
Copy

    public Object newComObj(
    	string progID,
    	string serverName = null
    )

    Public Function newComObj (
    	progID As String,
    	Optional serverName As String = Nothing
    ) As Object

    public:
    Object^ newComObj(
    	String^ progID,
    	String^ serverName = nullptr
    )

    member newComObj :
            progID : string *
            ?serverName : string
    (* Defaults:
            let _serverName = defaultArg serverName null
    *)
    -> Object

#### Parameters

progID String
  The programmatic identifier (ProgID) of the registered class to instantiate.
serverName String (Optional)
  An optional name that specifies the server on which to create the object.

#### Return Value

Object
A new COM/ActiveX object of the specified type.
Remarks
The progID argument can be a class identifier (CLSID) in standard GUID format with braces (e.g., "{0D43FE01-F093-11CF-8940-00A0C9054228}").
Example
The following code creates a Scripting.FileSystemObject instance and uses it to list the drives on the local machine. It assumes that an instance of ExtendedHostFunctions is exposed under the name "host" (see AddHostObject).
JavaScript
Copy

    var fso = host.newComObj('Scripting.FileSystemObject');
    var ConsoleT = host.type('System.Console');
    for (en = fso.Drives.GetEnumerator(); en.MoveNext();) {
        ConsoleT.WriteLine(en.Current.Path);
    }

See Also

#### Reference

ExtendedHostFunctions Class
Microsoft.ClearScript Namespace

Copyright © Microsoft Corporation. All rights reserved.

Send comments on this topic to Microsoft