C#检测并自动注册ocx
By
admin
at 2022-10-11 • 0人收藏 • 632人看过
using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp4 { public partial class Form1 : Form { [DllImport("st_curve.ocx")] public static extern int DllRegisterServer();//注册时用 [DllImport("st_curve.ocx")] public static extern int DllUnregisterServer();//取消注册时用 public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { Console.WriteLine(System.IO.Path.GetFullPath(@"st_curve.ocx")); RegistryKey rkTest = Registry.ClassesRoot.OpenSubKey(@"CLSID\{315E7F0E-6F9C-41A3-A669-A7E9626D7CA0}\"); if (rkTest == null) { int i = DllRegisterServer(); if (i >= 0) { //注册成功! Console.WriteLine("注册成功"); } else { //注册失败 Console.WriteLine("注册失败"); } } else { Console.WriteLine("已注册"); } } } }
登录后方可回帖