Type.GetTypeFromProgID Type.GetTypeFromProgID Type.GetTypeFromProgID Type.GetTypeFromProgID Method

定義

取得與指定的程式識別項 (ProgID) 相關聯的類型。Gets the type associated with the specified program identifier (ProgID).

多載

GetTypeFromProgID(String) GetTypeFromProgID(String) GetTypeFromProgID(String) GetTypeFromProgID(String)

取得與指定的程式識別項 (ProgID) 相關聯的類型;如果在載入 Type 時發生錯誤,則傳回 null。Gets the type associated with the specified program identifier (ProgID), returning null if an error is encountered while loading the Type.

GetTypeFromProgID(String, Boolean) GetTypeFromProgID(String, Boolean) GetTypeFromProgID(String, Boolean) GetTypeFromProgID(String, Boolean)

取得與指定的程式識別項 (ProgID) 相關聯的類型,並指定如果在載入類型時發生錯誤是否擲回例外狀況。Gets the type associated with the specified program identifier (ProgID), specifying whether to throw an exception if an error occurs while loading the type.

GetTypeFromProgID(String, String) GetTypeFromProgID(String, String) GetTypeFromProgID(String, String) GetTypeFromProgID(String, String)

從指定的伺服器中,取得與指定的程式識別項 (progID) 相關聯的類型;如果在載入類型時發生錯誤,則傳回 null。Gets the type associated with the specified program identifier (progID) from the specified server, returning null if an error is encountered while loading the type.

GetTypeFromProgID(String, String, Boolean) GetTypeFromProgID(String, String, Boolean) GetTypeFromProgID(String, String, Boolean) GetTypeFromProgID(String, String, Boolean)

從指定的伺服器中,取得與指定的程式識別項 (progID) 相關聯的類型,並指定如果在載入類型時發生錯誤是否擲回例外狀況。Gets the type associated with the specified program identifier (progID) from the specified server, specifying whether to throw an exception if an error occurs while loading the type.

GetTypeFromProgID(String) GetTypeFromProgID(String) GetTypeFromProgID(String) GetTypeFromProgID(String)

取得與指定的程式識別項 (ProgID) 相關聯的類型;如果在載入 Type 時發生錯誤,則傳回 null。Gets the type associated with the specified program identifier (ProgID), returning null if an error is encountered while loading the Type.

public:
 static Type ^ GetTypeFromProgID(System::String ^ progID);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID);
static member GetTypeFromProgID : string -> Type
Public Shared Function GetTypeFromProgID (progID As String) As Type

參數

progID
String String String String

要取得之類型的 ProgID。The ProgID of the type to get.

傳回

如果 progID 在登錄中是有效項目,而且有類型與它相關聯,則為與指定的 ProgID 相關聯的類型,否則為 nullThe type associated with the specified ProgID, if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

例外狀況

備註

這個方法提供用於 COM 支援。This method is provided for COM support. Progid 不會使用 Microsoft.NET Framework 中因為已取代命名空間的概念。ProgIDs are not used in the Microsoft .NET Framework because they have been superseded by the concept of namespace.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫端。Requires full trust for the immediate caller. 此成員不能由部分信任或不透明的程式碼。This member cannot be used by partially trusted or transparent code.

另請參閱

GetTypeFromProgID(String, Boolean) GetTypeFromProgID(String, Boolean) GetTypeFromProgID(String, Boolean) GetTypeFromProgID(String, Boolean)

取得與指定的程式識別項 (ProgID) 相關聯的類型,並指定如果在載入類型時發生錯誤是否擲回例外狀況。Gets the type associated with the specified program identifier (ProgID), specifying whether to throw an exception if an error occurs while loading the type.

public:
 static Type ^ GetTypeFromProgID(System::String ^ progID, bool throwOnError);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, bool throwOnError);
static member GetTypeFromProgID : string * bool -> Type
Public Shared Function GetTypeFromProgID (progID As String, throwOnError As Boolean) As Type

參數

progID
String String String String

要取得之類型的 ProgID。The ProgID of the type to get.

throwOnError
Boolean Boolean Boolean Boolean

true,擲回任何會發生的例外狀況。true to throw any exception that occurs.

-或--or- false 則忽略任何會發生的例外狀況。false to ignore any exception that occurs.

傳回

如果 progID 在登錄中是有效的項目,且有與其相關聯的類型,則為與指定的程式識別項 (progID) 相關聯的類型,否則為 nullThe type associated with the specified program identifier (ProgID), if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

例外狀況

指定的 ProgID 未註冊。The specified ProgID is not registered.

範例

下列範例會擷取藉由傳遞 ProgID,指定是否要擲回例外狀況,如果是無效的 ProgID 的型別。The following example retrieves a type by passing a ProgID, specifying whether to throw an exception if the ProgID is invalid. 此範例接著會顯示相關的 ProgID,以及任何適用的例外狀況訊息的 ClassID。The example then displays the ClassID related to the ProgID, along with any applicable exception message.

using namespace System;
int main()
{
   try
   {
      
      // Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
      String^ myString1 = "DIRECT.ddPalette.3";
      
      // Use a nonexistent ProgID WrongProgID.
      String^ myString2 = "WrongProgID";
      
      // Make a call to the method to get the type information of the given ProgID.
      Type^ myType1 = Type::GetTypeFromProgID( myString1, true );
      Console::WriteLine( "GUID for ProgID DirControl.DirList.1 is {0}.", myType1->GUID );
      
      // Throw an exception because the ProgID is invalid and the throwOnError
      // parameter is set to True.
      Type^ myType2 = Type::GetTypeFromProgID( myString2, true );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception occurred." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }

}

using System;
class MainApp 
{
    public static void Main()
    {
        try
        {
            // Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string myString1 ="DIRECT.ddPalette.3"; 
            // Use a nonexistent ProgID WrongProgID.
            string myString2 ="WrongProgID"; 
            // Make a call to the method to get the type information of the given ProgID.
            Type myType1 =Type.GetTypeFromProgID(myString1,true);
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
            // Throw an exception because the ProgID is invalid and the throwOnError  
            // parameter is set to True.
            Type myType2 =Type.GetTypeFromProgID(myString2,true);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source: {0}", e.Source);
            Console.WriteLine("Message: {0}", e.Message);
        }
    }
}
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use the ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim myString1 As String = "DIRECT.ddPalette.3"
            ' Use a nonexistent ProgID WrongProgID.
            Dim myString2 As String = "WrongProgID"
            ' Make a call to the method to get the type information of the given ProgID.
            Dim myType1 As Type = Type.GetTypeFromProgID(myString1, True)
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID.ToString())
            ' Throw an exception because the ProgID is invalid and the throwOnError 
            ' parameter is set to True.
            Dim myType2 As Type = Type.GetTypeFromProgID(myString2, True)
        Catch e As Exception
            Console.WriteLine("An exception occurred.")
            Console.WriteLine("Source: {0}", e.Source.ToString())
            Console.WriteLine("Message: {0}", e.Message.ToString())
        End Try
    End Sub 'Main 
End Class 'MainApp

備註

這個方法提供用於 COM 支援。This method is provided for COM support. 因為已取代命名空間的概念,程式識別碼不會使用 Microsoft.NET Framework 中。Program IDs are not used in Microsoft .NET Framework because they have been superseded by the concept of namespace.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫端。Requires full trust for the immediate caller. 此成員不能由部分信任或不透明的程式碼。This member cannot be used by partially trusted or transparent code.

另請參閱

GetTypeFromProgID(String, String) GetTypeFromProgID(String, String) GetTypeFromProgID(String, String) GetTypeFromProgID(String, String)

從指定的伺服器中,取得與指定的程式識別項 (progID) 相關聯的類型;如果在載入類型時發生錯誤,則傳回 null。Gets the type associated with the specified program identifier (progID) from the specified server, returning null if an error is encountered while loading the type.

public:
 static Type ^ GetTypeFromProgID(System::String ^ progID, System::String ^ server);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, string server);
static member GetTypeFromProgID : string * string -> Type
Public Shared Function GetTypeFromProgID (progID As String, server As String) As Type

參數

progID
String String String String

要取得之類型的 progID。The progID of the type to get.

server
String String String String

要載入類型的伺服器。The server from which to load the type. 如果伺服器名稱為 null,此方法將會自動還原成本機電腦 (Local Machine)。If the server name is null, this method automatically reverts to the local machine.

傳回

如果 progID 在登錄中是有效的項目,且有與其相關聯的類型,則為與指定的程式識別項 (progID) 相關聯的類型,否則為 nullThe type associated with the specified program identifier (progID), if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

例外狀況

範例

下列範例會擷取藉由傳遞的 ProgID 和伺服器名稱的型別。The following example retrieves a type by passing a ProgID and server name. 範例接著會顯示相關的 progid,ClassID,或如果 ProgID 或的伺服器名稱無效,會擲回例外狀況。The example then displays the ClassID related to the ProgID, or throws an exception if the ProgID or the server name is invalid.

using namespace System;
int main()
{
   try
   {
      
      // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl::DirList.1.
      String^ theProgramID = "DirControl.DirList.1";
      
      // Use the server name localhost.
      String^ theServer = "localhost";
      
      // Make a call to the method to get the type information for the given ProgID.
      Type^ myType = Type::GetTypeFromProgID( theProgramID, theServer );
      if ( myType == nullptr )
      {
         throw gcnew Exception( "Invalid ProgID or Server." );
      }
      Console::WriteLine( "GUID for ProgID DirControl.DirList.1 is {0}.", myType->GUID );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception occurred." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }

}

using System;
class MainApp 
{
    public static void Main()
    {
        try
        {
            // Use the ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string theProgramID ="DirControl.DirList.1"; 
            // Use the server name localhost.
            string theServer="localhost";
            // Make a call to the method to get the type information for the given ProgID.
            Type myType =Type.GetTypeFromProgID(theProgramID,theServer);
            if(myType==null)
            {
                throw new Exception("Invalid ProgID or Server.");
            }
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source: {0}" , e.Source);
            Console.WriteLine("Message: {0}" , e.Message);
        }		
    }
}
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use ProgID localhost\HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim theProgramID As String = "DirControl.DirList.1"
            ' Use Server name localhost.
            Dim theServer As String = "localhost"
            ' Make a call to the method to get the type information for the given ProgID.
            Dim myType As Type = Type.GetTypeFromProgID(theProgramID, theServer)
            If myType Is Nothing Then
                Throw New Exception("Invalid ProgID or server.")
            End If
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType.GUID.ToString())
        Catch e As Exception
            Console.WriteLine("An exception occurred.")
            Console.WriteLine("Source: {0}.", e.Source.ToString())
            Console.WriteLine("Message: {0}.", e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'MainApp

備註

這個方法提供用於 COM 支援。This method is provided for COM support. 因為已取代命名空間的概念,程式識別碼不會使用 Microsoft.NET Framework 中。Program IDs are not used in Microsoft .NET Framework because they have been superseded by the concept of namespace.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫端。Requires full trust for the immediate caller. 此成員不能由部分信任或不透明的程式碼。This member cannot be used by partially trusted or transparent code.

另請參閱

GetTypeFromProgID(String, String, Boolean) GetTypeFromProgID(String, String, Boolean) GetTypeFromProgID(String, String, Boolean) GetTypeFromProgID(String, String, Boolean)

從指定的伺服器中,取得與指定的程式識別項 (progID) 相關聯的類型,並指定如果在載入類型時發生錯誤是否擲回例外狀況。Gets the type associated with the specified program identifier (progID) from the specified server, specifying whether to throw an exception if an error occurs while loading the type.

public:
 static Type ^ GetTypeFromProgID(System::String ^ progID, System::String ^ server, bool throwOnError);
[System.Security.SecurityCritical]
public static Type GetTypeFromProgID (string progID, string server, bool throwOnError);
static member GetTypeFromProgID : string * string * bool -> Type
Public Shared Function GetTypeFromProgID (progID As String, server As String, throwOnError As Boolean) As Type

參數

progID
String String String String

要取得之 Type 的 progID。The progID of the Type to get.

server
String String String String

要載入類型的伺服器。The server from which to load the type. 如果伺服器名稱為 null,此方法將會自動還原成本機電腦 (Local Machine)。If the server name is null, this method automatically reverts to the local machine.

throwOnError
Boolean Boolean Boolean Boolean

true,擲回任何會發生的例外狀況。true to throw any exception that occurs.

-或--or- false 則忽略任何會發生的例外狀況。false to ignore any exception that occurs.

傳回

如果 progID 在登錄中是有效的項目,且有與其相關聯的類型,則為與指定的程式識別項 (progID) 相關聯的類型,否則為 nullThe type associated with the specified program identifier (progID), if progID is a valid entry in the registry and a type is associated with it; otherwise, null.

例外狀況

未註冊指定的 progID。The specified progID is not registered.

範例

下列範例會擷取藉由傳遞的 ProgID 和伺服器名稱的型別。The following example retrieves a type by passing a ProgID and server name. 此範例接著會顯示相關的 ProgID,指定是否要擲回例外狀況,如果 ProgID 或的伺服器名稱是無效的 ClassID。The example then displays the ClassID related to the ProgID, specifying whether to throw an exception if the ProgID or the server name is invalid.

using namespace System;
int main()
{
   try
   {
      
      // Use server localhost.
      String^ theServer = "localhost";
      
      // Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
      String^ myString1 = "DirControl.DirList.1";
      
      // Use a wrong ProgID WrongProgID.
      String^ myString2 = "WrongProgID";
      
      // Make a call to the method to get the type information for the given ProgID.
      Type^ myType1 = Type::GetTypeFromProgID( myString1, theServer, true );
      Console::WriteLine( "GUID for ProgID DirControl.DirList.1 is {0}.", myType1->GUID );
      
      // Throw an exception because the ProgID is invalid and the throwOnError
      // parameter is set to True.
      Type^ myType2 = Type::GetTypeFromProgID( myString2, theServer, true );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "An exception occurred. The ProgID is wrong." );
      Console::WriteLine( "Source: {0}", e->Source );
      Console::WriteLine( "Message: {0}", e->Message );
   }

}


using System;
class MainApp 
{
    public static void Main()
    {
        try
        {
            // Use server localhost.
            string theServer="localhost";
            // Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            string myString1 ="DirControl.DirList.1"; 
            // Use a wrong ProgID WrongProgID.
            string myString2 ="WrongProgID"; 
            // Make a call to the method to get the type information for the given ProgID.
            Type myType1 =Type.GetTypeFromProgID(myString1,theServer,true);
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID);
            // Throw an exception because the ProgID is invalid and the throwOnError 
            // parameter is set to True.
            Type myType2 =Type.GetTypeFromProgID(myString2, theServer, true);
        }
        catch(Exception e)
        {
            Console.WriteLine("An exception occurred. The ProgID is wrong.");
            Console.WriteLine("Source: {0}" , e.Source);
            Console.WriteLine("Message: {0}" , e.Message);
        }
    }
}
Imports System
Class MainApp
    Public Shared Sub Main()
        Try
            ' Use Server localhost.
            Dim theServer As String = "localhost"
            ' Use  ProgID HKEY_CLASSES_ROOT\DirControl.DirList.1.
            Dim myString1 As String = "DirControl.DirList.1"
            ' Use a wrong ProgID WrongProgID.
            Dim myString2 As String = "WrongProgID"
            ' Make a call to the method to get the type information for the given ProgID.
            Dim myType1 As Type = Type.GetTypeFromProgID(myString1, theServer, True)
            Console.WriteLine("GUID for ProgID DirControl.DirList.1 is {0}.", myType1.GUID.ToString())
            ' Throw an exception because the ProgID is invalid and the throwOnError 
            ' parameter is set to True.
            Dim myType2 As Type = Type.GetTypeFromProgID(myString2, theServer, True)
        Catch e As Exception
            Console.WriteLine("An exception occurred. The ProgID is wrong.")
            Console.WriteLine("Source: {0}", e.Source.ToString())
            Console.WriteLine("Message: {0}", e.Message.ToString())
        End Try
    End Sub 'Main 
End Class 'MainApp

備註

這個方法提供用於 COM 支援。This method is provided for COM support. 因為已取代命名空間的概念,程式識別碼不會使用 Microsoft.NET Framework 中。Program IDs are not used in Microsoft .NET Framework because they have been superseded by the concept of namespace.

安全性

SecurityCriticalAttribute
需要完全信任立即呼叫端。Requires full trust for the immediate caller. 此成員不能由部分信任或不透明的程式碼。This member cannot be used by partially trusted or transparent code.

另請參閱

適用於