扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
gacutil.exe /I Microsoft.SQLServer.DTSPkg80.dll |
[Guid("A39847F3-5845-4459-A25E-DE73A8E3CD48"), ComVisible(true)] [ProgId("DTS.SimpleTask")] public class SimpleTask : CustomTask { //implementation of custom task } |
[System.Runtime.InteropServices.ComRegisterFunctionAttribute()] static void RegisterServer(Type t) { //code to register custom task } |
[System.Runtime.InteropServices.ComUnregisterFunctionAttribute()] static void UnregisterServer(Type t) { //code to unregister custom task } |
using System; using System.Runtime.InteropServices; using Microsoft.SQLServer.DTSPkg80; using Microsoft.Win32; using System.Windows.Forms; [assembly:ClassInterface(ClassInterfaceType.AutoDual)] namespace DTS { [Guid("38ED4F80-9EF4-4752-8478-65D2DB3BA7DD"), ComVisible(true)] //GUID is created by using GUIDGEN.EXE [ProgId("DTS.SimpleCustomTask")] public class SimpleCustomTask : CustomTask { private string name; private string description; public SimpleCustomTask() { name = ""; description = "SimpleCustomTask description"; } public void Execute(object pPackage, object pPackageEvents, object pPackageLog, ref Microsoft.SQLServer.DTSPkg80.DTSTaskExecResult pTaskResult) { //Assume failure at the outset pTaskResult= DTSTaskExecResult.DTSTaskExecResult_Failure; try { Package2 package = (Package2) pPackage; PackageEvents packageEvents = (PackageEvents) pPackageEvents; PackageLog packageLog = (PackageLog) pPackageLog; MessageBox.Show(description); } //First catch COM exceptions, and then all other exceptions catch(System.Runtime.InteropServices.COMException e) { Console.WriteLine(e); } catch(System.Exception e) { Console.WriteLine(e); } //Return success pTaskResult = DTSTaskExecResult.DTSTaskExecResult_Success; } public string Description { get { return this.description; } set { this.description = value; } } public string Name { get { return name; } set { this.name = value; } } public Microsoft.SQLServer.DTSPkg80.Properties Properties { get { return null; } } [System.Runtime.InteropServices.ComVisible(false)] override public string ToString() { return base.ToString(); } //Registration function for custom task. [System.Runtime.InteropServices.ComRegisterFunctionAttribute()] static void RegisterServer(Type t) { try { const string TASK_CACHE = "Software\\Microsoft\\Microsoft SQL Server\\80\\DTS\\Enumeration\\Tasks"; const string CATID_DTSCustomTask = "{10020200-EB1C-11CF-AE6E-00AA004A34D5}"; string guid = "{" + t.GUID.ToString() + "}"; guid = guid.ToUpper(); Console.WriteLine("RegisterServer {0}", guid); RegistryKey root; RegistryKey rk; RegistryKey nrk; // Add COM Category in HKEY_CLASSES_ROOT root = Registry.ClassesRoot; rk = root.OpenSubKey("CLSID\\" + guid + "\\Implemented Categories", true); nrk = rk.CreateSubKey(CATID_DTSCustomTask); nrk.Close(); rk.Close(); root.Close(); // Add to DTS Cache in HKEY_CURRENT_USER root = Registry.CurrentUser; rk = root.OpenSubKey(TASK_CACHE, true); nrk = rk.CreateSubKey(guid); nrk.SetValue("", t.FullName); nrk.Close(); rk.Close(); root.Close(); SimpleCustomTask ct = new SimpleCustomTask(); root = Registry.ClassesRoot; rk = root.OpenSubKey("CLSID\\" + guid, true); rk.SetValue("DTSTaskDescription", ct.description); nrk.Close(); rk.Close(); root.Close(); } catch(Exception e) { System.Console.WriteLine(e.ToString()); } } //Unregistration function for custom task. [System.Runtime.InteropServices.ComUnregisterFunctionAttribute()] static void UnregisterServer(Type t) { try { const string TASK_CACHE = "Software\\Microsoft\\Microsoft SQL Server\\80\\DTS\\Enumeration\\Tasks"; string guid = "{" + t.GUID.ToString() + "}"; guid = guid.ToUpper(); Console.WriteLine("UnregisterServer {0}", guid); RegistryKey root; RegistryKey rk; // Delete from DTS Cache in HKEY_CURRENT_USER root = Registry.CurrentUser; rk = root.OpenSubKey(TASK_CACHE, true); rk.DeleteSubKey(guid, false); rk.Close(); root.Close(); } catch(Exception e) { System.Console.WriteLine(e.ToString()); } } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者