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