1. 程式人生 > >C#寫的COM元件註冊與反註冊類

C#寫的COM元件註冊與反註冊類

指定註冊或反註冊的位置(位於登錄檔中):

public class ClassCommand
{
	[ComRegisterFunction()]
	public static void RegistryCommand(string regKey)
	{
		Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(regKey.Substring(18) + "\\Implemented Categories\\" + "{E5BDE9F2-167C-49BD-B05C-BCDF47B297FF}");
	}

	[ComUnregisterFunction()]
	public static void UnregisterCommand(string regKey)
	{
		Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(regKey.Substring(18) + "\\Implemented Categories\\" + "{E5BDE9F2-167C-49BD-B05C-BCDF47B297FF}");
	}
}

使用方法示例:

[ClassInterface(ClassInterfaceType.None)]
[Guid("9DD159BA-78C1-4FA1-8FE0-B1FBB6EB41F6")]
public class CTestXXZX : ClassCommand
{
	
}