使用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"

相关文章:

  • 2021-12-23
  • 2021-08-29
  • 2021-06-27
  • 2021-08-08
  • 2021-10-27
  • 2022-12-23
  • 2021-12-11
  • 2021-06-06
猜你喜欢
  • 2021-08-10
  • 2021-10-21
  • 2021-12-10
  • 2022-01-05
  • 2021-12-22
  • 2021-11-26
  • 2022-12-23
相关资源
相似解决方案