zoukankan      html  css  js  c++  java
  • 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组件注册失败");
                    }
             */
        }
  • 相关阅读:
    一些端口
    outlook 的微软手册
    目录摘要
    L2TP的包过滤规则
    outlook 的外出时助理程序对外部邮箱不起作用。1个解决办法和另外一个可能性
    用editplus 正则表达式修改联系人表
    Cisco NAT的理解。
    outlook 2003 无法记住密码
    ERD commander 2005的下载地址。
    outlook 2003启用日志记录排除故障。
  • 原文地址:https://www.cnblogs.com/shenchao/p/6506277.html
Copyright © 2011-2022 走看看