runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

使用InstallUtil安装WINDOWS服务时,会被360木马防火墙阻止。不好跟踪到安装结果。

复制代码
 //使用.NET的 InstallUtil.exe 来安装服务
            string sInstallUtil = System.Environment.GetEnvironmentVariable("WINDIR") + @"\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe";
            if (!File.Exists(sInstallUtil))
            {
                MessageBox.Show("InstallUtil 工具不存在。");
                return;
            }

ProcessStartInfo pStart = new ProcessStartInfo(sInstallUtil);
                Process pRoc = new Process();

                    pStart.Arguments = " " + svrPath;
                    pStart.UseShellExecute = false;
                    pStart.CreateNoWindow = false;

                    pRoc.StartInfo = pStart;
                    pRoc.Start();
                    pRoc.WaitForExit();
复制代码

换成AssemblyInstaller,

//被360木马防火墙阻止时,会引发异常。
                    IDictionary mySavedState = new Hashtable();
                    AssemblyInstaller myAssemblyInstaller = new AssemblyInstaller();
                    myAssemblyInstaller.UseNewContext = true;
                    myAssemblyInstaller.Path = svrPath;
                    myAssemblyInstaller.Install(mySavedState);
                    myAssemblyInstaller.Commit(mySavedState);
                    myAssemblyInstaller.Dispose();

exp.GetType().Name == "Win32Exception"

posted on   runliuv  阅读(875)  评论(1编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示