using AUTS.Services.Manager; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Web; using System.Web.Configuration; using System.Web.Mvc; namespace Face.Web.Areas.App.Controllers { public class ProgramController : Controller { // GET: App/Program public ActionResult Index() { return View(); } [HttpPost] public ActionResult Start(string programPath) { ProcessStartInfo startInfo = new ProcessStartInfo(); if (string.IsNullOrEmpty(programPath)) { ViewBag.Message = "No program path provided"; return View("Index"); } try { startInfo.UseShellExecute = true; startInfo.Verb = "runas"; //这行代码将提升权限 //startInfo.FileName = Assembly.GetEntryAssembly().Location; startInfo.WorkingDirectory = Environment.CurrentDirectory; Process.Start(programPath); Logs.WriteLog("重新启动进成功"); ViewBag.Message = "Program started successfully"; //Process.Start(programPath); Environment.Exit(0); } catch (System.Exception ex) { ViewBag.Message = $"Failed to start program: {ex.Message}"; Logs.WriteLog("重新启动进成功"+ex); } return View("Index"); } [HttpPost] public ActionResult Stop(string programName) { if (string.IsNullOrEmpty(programName)) { ViewBag.Message = "No program name provided"; return View("Index"); } try { Process[] processes = Process.GetProcessesByName(programName); foreach (var process in processes) { process.Kill(); Logs.WriteLog("关闭启动进成功"); } ViewBag.Message = "Program stopped successfully"; } catch (System.Exception ex) { ViewBag.Message = $"Failed to stop program: {ex.Message}"; Logs.WriteLog("关闭启动进" + ex); } return View("Index"); } } }