private void btn_install_Click(object sender, EventArgs e) { if (!flag) { lab_msg.Text = "请先选择正确的服务安装程序!"; } else { if (!ServiceIsExisted(svcname)) { string[] args = { filepath }; ServiceController sCtr = new ServiceController(svcname);
try { ManagedInstallerClass.InstallHelper(args); } catch (Exception ex) { MessageBox.Show("安装失败,请重试!"); return; } MessageBox.Show("安装成功!"); // Application.Exit();
} else { MessageBox.Show("已经安装了该服务,请勿重复安装!"); return; } } } private bool ServiceIsExisted(string svcName) { ServiceController[] services = ServiceController.GetServices(); foreach (ServiceController s in services) { if (s.ServiceName == svcName) { return true; } } return false; } //卸载 private void btn_delete_Click(object sender, EventArgs e) { try { string[] cmdline = { };
TransactedInstaller transactedInstaller = new TransactedInstaller(); AssemblyInstaller assemblyInstaller = new AssemblyInstaller(filepath, cmdline); transactedInstaller.Installers.Add(assemblyInstaller); transactedInstaller.Uninstall(null); MessageBox.Show("卸载成功"); //Application.Exit();
} catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } }
|