COM.new Method

Creates an instance of the COM class that can be attached to the COM class and optionally instantiates a COM object on a specified computer.

Syntax

public void new([str className, str computerName])

Run On

Called

Parameters

  • className
    Type: str
    The name of the class to use to create the instance of the COM class; optional.
    If this parameter is omitted, no COM object is instantiated for the COM class. To attach a COM object to the COM class, use the attach method.
  • computerName
    Type: str
    The name of the remote computer on which to instantiate the COM object; optional.
    If this parameter is omitted, the COM object is instantiated on the local computer. If the computer name is specified, the DCOM system component must be installed on both the local computer and the remote computer. The specific COM object must support DCOM, and it must be correctly configured on both the local computer and the remote computer.
    The system component is a standard component of MicrosoftWindows 98, Windows NT, and later versions. In Windows 95, the DCOM system component must be installed.

Remarks

The class name of a COM object is either its programmatic identifier (ProgID) or its class identifier (CLSID):

  • ProgIDs have the following format: program.component.version

  • CLSIDs are 128-bit values and have the following format: {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

If an attacker can control input to the new method, a security risk exists. Therefore, this method runs under Code Access Security. Calls to this method on the server require permission from the InteropPermission class. Make sure that the user has development privileges by setting the security key to SysDevelopment on the control that calls this method.

Examples

This example calls the GetFileName method from the Scripting.FileSystemObject COM object.

void COMExample() 
{ 
    COM               com; 
    str               result; 
    InteropPermission perm; 
  
    // Set the code access permission to help protect the use of the 
    // COM object. 
    perm = new InteropPermission(InteropKind::ComInterop); 
    if (perm == null) 
    { 
        return; 
    } 
    // Permission scope starts here. 
    perm.assert(); 
  
    com = new COM("Scripting.FileSystemObject"); 
    if (com != null) 
    { 
        result = com.GetFileName(@"c:\boot.ini"); 
    } 
  
    // Close the code access permission scope. 
    CodeAccessPermission::revertAssert(); 
}

See Also

Reference

COM Class