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组件注册失败");
                    }
             */
        }
  • 相关阅读:
    APP-Android:APK
    软件-版本控制:VCS(版本控制系统)
    协议-网络-安全协议-SSH(安全外壳协议):百科
    un-解决方案-BIM:百科
    MySQL:常用语句
    rsync+inotify-tools文件实时同步
    Java实现 Leetcode 169 求众数
    Java实现 Leetcode 169 求众数
    Java实现 LeetCode 137 只出现一次的数字
    Java实现 LeetCode 137 只出现一次的数字
  • 原文地址:https://www.cnblogs.com/shenchao/p/6506277.html
Copyright © 2011-2022 走看看