• C#:注册组件 (cmd)


        public class ComRegistor
        {
            public static string classID = "CLSID\{479A1AAC-C148-40BB-9868-A9773DA66AF9}\";//SWFToImage组件注册ID
    
            /// <summary>
            /// 注册组件
            /// </summary>
            /// <param name="fileFullName">文件完整路径</param>
            /// <param name="dllName">动态库名</param>
            public static bool Register(string fileFullName, string dllName)
            {
                bool rev = false;
                try
                {
                    Process p = new Process();
                    p.StartInfo.FileName = "cmd.exe";
                    p.StartInfo.UseShellExecute = false;
                    p.StartInfo.RedirectStandardInput = true;
                    p.StartInfo.RedirectStandardOutput = true;
                    p.StartInfo.RedirectStandardError = true;
                    p.StartInfo.CreateNoWindow = false;
                    p.Start();
                    p.StandardInput.WriteLine(@"DELETE " + fileFullName + @" %windir%system32");
                    p.StandardInput.WriteLine(@"COPY " + fileFullName + @" %windir%system32");
                    p.StandardInput.WriteLine(@"regsvr32 /s %windir%system32" + dllName);
                    p.StandardInput.WriteLine("exit");
                    string ReturnInfo = p.StandardOutput.ReadToEnd();
                    p.Close();
                    rev = true;
                }
                catch (Exception e)
                {
                    rev = false;
                }
    
                return rev;
            }
            /// <summary>
            /// 判别某一组件是否已注册
            /// </summary>
            /// <returns></returns>
            public static bool IsRegister(string classID)
            {
                bool result = false;
                RegistryKey rkTest = Registry.ClassesRoot.OpenSubKey(classID);
                if (rkTest != null)
                {
                    result = true;
                }
                return result;
            }
    
            /*
             
                    if (!ComRegistor.IsRegister(ComRegistor.classID))
                    {
                        if (File.Exists(System.Environment.SystemDirectory + Path.DirectorySeparatorChar + "SWFToImage.DLL") == true)
                        {
                            File.Delete(System.Environment.SystemDirectory + Path.DirectorySeparatorChar + "SWFToImage.DLL");
                        }
    
                        
                        ComRegistor.Register(Application.StartupPath + @"RegSvrSWFToImage.Dll", "SWFToImage.Dll");
    
                        if (!ComRegistor.IsRegister(ComRegistor.classID))
                            MessageBox.Show("COM组件注册失败");
                    }
             */
        }
  • 相关阅读:
    ssm框架配置文件
    接口调用post请求参数在body中
    mysql三种连接方式
    jwt认证登录
    JWT工具类
    token的创建及解析
    IIS目录
    C# 增加多个分部类
    计算机知识
    Kibana 的安装(Windows版本)
  • 原文地址:https://www.cnblogs.com/shenchao/p/6506277.html
Copyright © 2020-2023  润新知