ApplicationHost.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. using MediaBrowser.Api;
  2. using MediaBrowser.Common;
  3. using MediaBrowser.Common.Configuration;
  4. using MediaBrowser.Common.Constants;
  5. using MediaBrowser.Common.Extensions;
  6. using MediaBrowser.Common.Implementations;
  7. using MediaBrowser.Common.Implementations.ScheduledTasks;
  8. using MediaBrowser.Common.IO;
  9. using MediaBrowser.Common.MediaInfo;
  10. using MediaBrowser.Common.Net;
  11. using MediaBrowser.Controller;
  12. using MediaBrowser.Controller.Configuration;
  13. using MediaBrowser.Controller.Drawing;
  14. using MediaBrowser.Controller.Entities;
  15. using MediaBrowser.Controller.IO;
  16. using MediaBrowser.Controller.Library;
  17. using MediaBrowser.Controller.Localization;
  18. using MediaBrowser.Controller.MediaInfo;
  19. using MediaBrowser.Controller.Persistence;
  20. using MediaBrowser.Controller.Plugins;
  21. using MediaBrowser.Controller.Providers;
  22. using MediaBrowser.Controller.Resolvers;
  23. using MediaBrowser.Controller.Session;
  24. using MediaBrowser.Controller.Sorting;
  25. using MediaBrowser.Controller.Updates;
  26. using MediaBrowser.Controller.Weather;
  27. using MediaBrowser.IsoMounter;
  28. using MediaBrowser.Model.IO;
  29. using MediaBrowser.Model.MediaInfo;
  30. using MediaBrowser.Model.System;
  31. using MediaBrowser.Model.Updates;
  32. using MediaBrowser.Providers;
  33. using MediaBrowser.Server.Implementations;
  34. using MediaBrowser.Server.Implementations.BdInfo;
  35. using MediaBrowser.Server.Implementations.Configuration;
  36. using MediaBrowser.Server.Implementations.HttpServer;
  37. using MediaBrowser.Server.Implementations.IO;
  38. using MediaBrowser.Server.Implementations.Library;
  39. using MediaBrowser.Server.Implementations.Localization;
  40. using MediaBrowser.Server.Implementations.MediaEncoder;
  41. using MediaBrowser.Server.Implementations.Persistence;
  42. using MediaBrowser.Server.Implementations.Providers;
  43. using MediaBrowser.Server.Implementations.ServerManager;
  44. using MediaBrowser.Server.Implementations.Session;
  45. using MediaBrowser.Server.Implementations.Updates;
  46. using MediaBrowser.Server.Implementations.WebSocket;
  47. using MediaBrowser.ServerApplication.Implementations;
  48. using MediaBrowser.WebDashboard.Api;
  49. using System;
  50. using System.Collections.Generic;
  51. using System.Diagnostics;
  52. using System.IO;
  53. using System.Linq;
  54. using System.Reflection;
  55. using System.Threading;
  56. using System.Threading.Tasks;
  57. namespace MediaBrowser.ServerApplication
  58. {
  59. /// <summary>
  60. /// Class CompositionRoot
  61. /// </summary>
  62. public class ApplicationHost : BaseApplicationHost<ServerApplicationPaths>, IServerApplicationHost
  63. {
  64. internal const int UdpServerPort = 7359;
  65. /// <summary>
  66. /// Gets the server kernel.
  67. /// </summary>
  68. /// <value>The server kernel.</value>
  69. protected Kernel ServerKernel { get; set; }
  70. /// <summary>
  71. /// Gets the server configuration manager.
  72. /// </summary>
  73. /// <value>The server configuration manager.</value>
  74. public IServerConfigurationManager ServerConfigurationManager
  75. {
  76. get { return (IServerConfigurationManager)ConfigurationManager; }
  77. }
  78. /// <summary>
  79. /// Gets the name of the log file prefix.
  80. /// </summary>
  81. /// <value>The name of the log file prefix.</value>
  82. protected override string LogFilePrefixName
  83. {
  84. get { return "server"; }
  85. }
  86. /// <summary>
  87. /// Gets the name of the web application that can be used for url building.
  88. /// All api urls will be of the form {protocol}://{host}:{port}/{appname}/...
  89. /// </summary>
  90. /// <value>The name of the web application.</value>
  91. public string WebApplicationName
  92. {
  93. get { return "mediabrowser"; }
  94. }
  95. /// <summary>
  96. /// Gets the HTTP server URL prefix.
  97. /// </summary>
  98. /// <value>The HTTP server URL prefix.</value>
  99. public string HttpServerUrlPrefix
  100. {
  101. get
  102. {
  103. return "http://+:" + ServerConfigurationManager.Configuration.HttpServerPortNumber + "/" + WebApplicationName + "/";
  104. }
  105. }
  106. /// <summary>
  107. /// Gets the configuration manager.
  108. /// </summary>
  109. /// <returns>IConfigurationManager.</returns>
  110. protected override IConfigurationManager GetConfigurationManager()
  111. {
  112. return new ServerConfigurationManager(ApplicationPaths, LogManager, XmlSerializer);
  113. }
  114. /// <summary>
  115. /// Gets or sets the installation manager.
  116. /// </summary>
  117. /// <value>The installation manager.</value>
  118. private IInstallationManager InstallationManager { get; set; }
  119. /// <summary>
  120. /// Gets or sets the server manager.
  121. /// </summary>
  122. /// <value>The server manager.</value>
  123. private IServerManager ServerManager { get; set; }
  124. /// <summary>
  125. /// Gets or sets the user manager.
  126. /// </summary>
  127. /// <value>The user manager.</value>
  128. public IUserManager UserManager { get; set; }
  129. /// <summary>
  130. /// Gets or sets the library manager.
  131. /// </summary>
  132. /// <value>The library manager.</value>
  133. internal ILibraryManager LibraryManager { get; set; }
  134. /// <summary>
  135. /// Gets or sets the directory watchers.
  136. /// </summary>
  137. /// <value>The directory watchers.</value>
  138. private IDirectoryWatchers DirectoryWatchers { get; set; }
  139. /// <summary>
  140. /// Gets or sets the provider manager.
  141. /// </summary>
  142. /// <value>The provider manager.</value>
  143. private IProviderManager ProviderManager { get; set; }
  144. /// <summary>
  145. /// Gets or sets the zip client.
  146. /// </summary>
  147. /// <value>The zip client.</value>
  148. private IZipClient ZipClient { get; set; }
  149. /// <summary>
  150. /// Gets or sets the HTTP server.
  151. /// </summary>
  152. /// <value>The HTTP server.</value>
  153. private IHttpServer HttpServer { get; set; }
  154. /// <summary>
  155. /// Gets or sets the media encoder.
  156. /// </summary>
  157. /// <value>The media encoder.</value>
  158. private IMediaEncoder MediaEncoder { get; set; }
  159. private ILocalizationManager LocalizationManager { get; set; }
  160. /// <summary>
  161. /// Gets or sets the user data repository.
  162. /// </summary>
  163. /// <value>The user data repository.</value>
  164. private IUserDataRepository UserDataRepository { get; set; }
  165. private IUserRepository UserRepository { get; set; }
  166. internal IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
  167. private IItemRepository ItemRepository { get; set; }
  168. /// <summary>
  169. /// The full path to our startmenu shortcut
  170. /// </summary>
  171. protected override string ProductShortcutPath
  172. {
  173. get { return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Media Browser 3", "Media Browser Server.lnk"); }
  174. }
  175. private Task<IHttpServer> _httpServerCreationTask;
  176. /// <summary>
  177. /// Runs the startup tasks.
  178. /// </summary>
  179. /// <returns>Task.</returns>
  180. public override async Task RunStartupTasks()
  181. {
  182. await base.RunStartupTasks().ConfigureAwait(false);
  183. DirectoryWatchers.Start();
  184. Logger.Info("Core startup complete");
  185. Parallel.ForEach(GetExports<IServerEntryPoint>(), entryPoint =>
  186. {
  187. try
  188. {
  189. entryPoint.Run();
  190. }
  191. catch (Exception ex)
  192. {
  193. Logger.ErrorException("Error in {0}", ex, entryPoint.GetType().Name);
  194. }
  195. });
  196. }
  197. /// <summary>
  198. /// Called when [logger loaded].
  199. /// </summary>
  200. protected override void OnLoggerLoaded()
  201. {
  202. base.OnLoggerLoaded();
  203. _httpServerCreationTask = Task.Run(() => ServerFactory.CreateServer(this, LogManager, "Media Browser", "dashboard/index.html"));
  204. }
  205. /// <summary>
  206. /// Registers resources that classes will depend on
  207. /// </summary>
  208. /// <returns>Task.</returns>
  209. protected override async Task RegisterResources()
  210. {
  211. ServerKernel = new Kernel();
  212. await base.RegisterResources().ConfigureAwait(false);
  213. RegisterSingleInstance<IHttpResultFactory>(new HttpResultFactory(LogManager));
  214. RegisterSingleInstance<IServerApplicationHost>(this);
  215. RegisterSingleInstance<IServerApplicationPaths>(ApplicationPaths);
  216. RegisterSingleInstance(ServerKernel);
  217. RegisterSingleInstance(ServerConfigurationManager);
  218. RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger));
  219. RegisterSingleInstance<IIsoManager>(() => new PismoIsoManager(Logger));
  220. RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
  221. ZipClient = new DotNetZipClient();
  222. RegisterSingleInstance(ZipClient);
  223. UserDataRepository = new SqliteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);
  224. RegisterSingleInstance(UserDataRepository);
  225. UserRepository = new SqliteUserRepository(ApplicationPaths, JsonSerializer, LogManager);
  226. RegisterSingleInstance(UserRepository);
  227. DisplayPreferencesRepository = new SqliteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
  228. RegisterSingleInstance(DisplayPreferencesRepository);
  229. ItemRepository = new SqliteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
  230. RegisterSingleInstance(ItemRepository);
  231. UserManager = new UserManager(Logger, ServerConfigurationManager);
  232. RegisterSingleInstance(UserManager);
  233. LibraryManager = new LibraryManager(Logger, TaskManager, UserManager, ServerConfigurationManager, UserDataRepository);
  234. RegisterSingleInstance(LibraryManager);
  235. InstallationManager = new InstallationManager(HttpClient, PackageManager, JsonSerializer, Logger, this);
  236. RegisterSingleInstance(InstallationManager);
  237. DirectoryWatchers = new DirectoryWatchers(LogManager, TaskManager, LibraryManager, ServerConfigurationManager);
  238. RegisterSingleInstance(DirectoryWatchers);
  239. ProviderManager = new ProviderManager(HttpClient, ServerConfigurationManager, DirectoryWatchers, LogManager);
  240. RegisterSingleInstance(ProviderManager);
  241. RegisterSingleInstance<ILibrarySearchEngine>(() => new LuceneSearchEngine(ApplicationPaths, LogManager, LibraryManager));
  242. MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), ZipClient, ApplicationPaths, JsonSerializer);
  243. RegisterSingleInstance(MediaEncoder);
  244. var clientConnectionManager = new SessionManager(UserDataRepository, ServerConfigurationManager, Logger, UserRepository);
  245. RegisterSingleInstance<ISessionManager>(clientConnectionManager);
  246. HttpServer = await _httpServerCreationTask.ConfigureAwait(false);
  247. RegisterSingleInstance(HttpServer, false);
  248. ServerManager = new ServerManager(this, JsonSerializer, Logger, ServerConfigurationManager);
  249. RegisterSingleInstance(ServerManager);
  250. LocalizationManager = new LocalizationManager(ServerConfigurationManager);
  251. RegisterSingleInstance(LocalizationManager);
  252. var displayPreferencesTask = Task.Run(async () => await ConfigureDisplayPreferencesRepositories().ConfigureAwait(false));
  253. var itemsTask = Task.Run(async () => await ConfigureItemRepositories().ConfigureAwait(false));
  254. var userdataTask = Task.Run(async () => await ConfigureUserDataRepositories().ConfigureAwait(false));
  255. var userTask = Task.Run(async () => await ConfigureUserRepositories().ConfigureAwait(false));
  256. await Task.WhenAll(itemsTask, userTask, displayPreferencesTask, userdataTask).ConfigureAwait(false);
  257. SetKernelProperties();
  258. }
  259. /// <summary>
  260. /// Sets the kernel properties.
  261. /// </summary>
  262. private void SetKernelProperties()
  263. {
  264. ServerKernel.ImageManager = new ImageManager(LogManager.GetLogger("ImageManager"),
  265. ApplicationPaths, ItemRepository);
  266. Parallel.Invoke(
  267. () => ServerKernel.FFMpegManager = new FFMpegManager(ApplicationPaths, MediaEncoder, LibraryManager, Logger, ItemRepository),
  268. () => ServerKernel.WeatherProviders = GetExports<IWeatherProvider>(),
  269. () => ServerKernel.ImageManager.ImageEnhancers = GetExports<IImageEnhancer>().OrderBy(e => e.Priority).ToArray(),
  270. () => LocalizedStrings.StringFiles = GetExports<LocalizedStringData>(),
  271. SetStaticProperties
  272. );
  273. }
  274. /// <summary>
  275. /// Configures the repositories.
  276. /// </summary>
  277. /// <returns>Task.</returns>
  278. private async Task ConfigureDisplayPreferencesRepositories()
  279. {
  280. await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
  281. }
  282. /// <summary>
  283. /// Configures the item repositories.
  284. /// </summary>
  285. /// <returns>Task.</returns>
  286. private async Task ConfigureItemRepositories()
  287. {
  288. await ItemRepository.Initialize().ConfigureAwait(false);
  289. ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
  290. }
  291. /// <summary>
  292. /// Configures the user data repositories.
  293. /// </summary>
  294. /// <returns>Task.</returns>
  295. private Task ConfigureUserDataRepositories()
  296. {
  297. return UserDataRepository.Initialize();
  298. }
  299. /// <summary>
  300. /// Configures the user repositories.
  301. /// </summary>
  302. /// <returns>Task.</returns>
  303. private async Task ConfigureUserRepositories()
  304. {
  305. await UserRepository.Initialize().ConfigureAwait(false);
  306. ((UserManager)UserManager).UserRepository = UserRepository;
  307. }
  308. /// <summary>
  309. /// Dirty hacks
  310. /// </summary>
  311. private void SetStaticProperties()
  312. {
  313. // For now there's no real way to inject these properly
  314. BaseItem.Logger = LogManager.GetLogger("BaseItem");
  315. BaseItem.ConfigurationManager = ServerConfigurationManager;
  316. BaseItem.LibraryManager = LibraryManager;
  317. BaseItem.ProviderManager = ProviderManager;
  318. BaseItem.LocalizationManager = LocalizationManager;
  319. BaseItem.ItemRepository = ItemRepository;
  320. User.XmlSerializer = XmlSerializer;
  321. User.UserManager = UserManager;
  322. LocalizedStrings.ApplicationPaths = ApplicationPaths;
  323. }
  324. /// <summary>
  325. /// Finds the parts.
  326. /// </summary>
  327. protected override void FindParts()
  328. {
  329. if (IsFirstRun)
  330. {
  331. RegisterServerWithAdministratorAccess();
  332. }
  333. base.FindParts();
  334. HttpServer.Init(GetExports<IRestfulService>(false));
  335. ServerManager.AddWebSocketListeners(GetExports<IWebSocketListener>(false));
  336. StartServer(true);
  337. LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(),
  338. GetExports<IVirtualFolderCreator>(),
  339. GetExports<IItemResolver>(),
  340. GetExports<IIntroProvider>(),
  341. GetExports<IBaseItemComparer>(),
  342. GetExports<ILibraryPrescanTask>(),
  343. GetExports<ILibraryPostScanTask>(),
  344. GetExports<IMetadataSaver>());
  345. ProviderManager.AddMetadataProviders(GetExports<BaseMetadataProvider>().ToArray());
  346. }
  347. /// <summary>
  348. /// Starts the server.
  349. /// </summary>
  350. /// <param name="retryOnFailure">if set to <c>true</c> [retry on failure].</param>
  351. private void StartServer(bool retryOnFailure)
  352. {
  353. try
  354. {
  355. ServerManager.Start();
  356. }
  357. catch
  358. {
  359. if (retryOnFailure)
  360. {
  361. RegisterServerWithAdministratorAccess();
  362. StartServer(false);
  363. }
  364. else
  365. {
  366. throw;
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// Called when [configuration updated].
  372. /// </summary>
  373. /// <param name="sender">The sender.</param>
  374. /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  375. protected override void OnConfigurationUpdated(object sender, EventArgs e)
  376. {
  377. base.OnConfigurationUpdated(sender, e);
  378. if (!string.Equals(HttpServer.UrlPrefix, HttpServerUrlPrefix, StringComparison.OrdinalIgnoreCase))
  379. {
  380. NotifyPendingRestart();
  381. }
  382. else if (!ServerManager.SupportsNativeWebSocket && ServerManager.WebSocketPortNumber != ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber)
  383. {
  384. NotifyPendingRestart();
  385. }
  386. }
  387. /// <summary>
  388. /// Restarts this instance.
  389. /// </summary>
  390. public override void Restart()
  391. {
  392. App.Instance.Restart();
  393. }
  394. /// <summary>
  395. /// Gets or sets a value indicating whether this instance can self update.
  396. /// </summary>
  397. /// <value><c>true</c> if this instance can self update; otherwise, <c>false</c>.</value>
  398. public override bool CanSelfUpdate
  399. {
  400. get { return ConfigurationManager.CommonConfiguration.EnableAutoUpdate; }
  401. }
  402. /// <summary>
  403. /// Checks for update.
  404. /// </summary>
  405. /// <param name="cancellationToken">The cancellation token.</param>
  406. /// <param name="progress">The progress.</param>
  407. /// <returns>Task{CheckForUpdateResult}.</returns>
  408. public async override Task<CheckForUpdateResult> CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress<double> progress)
  409. {
  410. var availablePackages = await PackageManager.GetAvailablePackages(CancellationToken.None).ConfigureAwait(false);
  411. var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, ConfigurationManager.CommonConfiguration.SystemUpdateLevel);
  412. return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } :
  413. new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false };
  414. }
  415. /// <summary>
  416. /// Gets the composable part assemblies.
  417. /// </summary>
  418. /// <returns>IEnumerable{Assembly}.</returns>
  419. protected override IEnumerable<Assembly> GetComposablePartAssemblies()
  420. {
  421. // Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
  422. // This will prevent the .dll file from getting locked, and allow us to replace it when needed
  423. foreach (var pluginAssembly in Directory
  424. .EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
  425. .Select(LoadAssembly).Where(a => a != null))
  426. {
  427. yield return pluginAssembly;
  428. }
  429. // Include composable parts in the Api assembly
  430. yield return typeof(ApiEntryPoint).Assembly;
  431. // Include composable parts in the Dashboard assembly
  432. yield return typeof(DashboardInfo).Assembly;
  433. // Include composable parts in the Model assembly
  434. yield return typeof(SystemInfo).Assembly;
  435. // Include composable parts in the Common assembly
  436. yield return typeof(IApplicationHost).Assembly;
  437. // Include composable parts in the Controller assembly
  438. yield return typeof(Kernel).Assembly;
  439. // Include composable parts in the Providers assembly
  440. yield return typeof(ImagesByNameProvider).Assembly;
  441. // Common implementations
  442. yield return typeof(TaskManager).Assembly;
  443. // Server implementations
  444. yield return typeof(ServerApplicationPaths).Assembly;
  445. // Include composable parts in the running assembly
  446. yield return GetType().Assembly;
  447. }
  448. private readonly string _systemId = Environment.MachineName.GetMD5().ToString();
  449. /// <summary>
  450. /// Gets the system status.
  451. /// </summary>
  452. /// <returns>SystemInfo.</returns>
  453. public virtual SystemInfo GetSystemInfo()
  454. {
  455. return new SystemInfo
  456. {
  457. HasPendingRestart = HasPendingRestart,
  458. Version = ApplicationVersion.ToString(),
  459. IsNetworkDeployed = CanSelfUpdate,
  460. WebSocketPortNumber = ServerManager.WebSocketPortNumber,
  461. SupportsNativeWebSocket = ServerManager.SupportsNativeWebSocket,
  462. FailedPluginAssemblies = FailedAssemblies.ToArray(),
  463. InProgressInstallations = InstallationManager.CurrentInstallations.Select(i => i.Item1).ToArray(),
  464. CompletedInstallations = InstallationManager.CompletedInstallations.ToArray(),
  465. Id = _systemId,
  466. ProgramDataPath = ApplicationPaths.ProgramDataPath
  467. };
  468. }
  469. /// <summary>
  470. /// Shuts down.
  471. /// </summary>
  472. public override void Shutdown()
  473. {
  474. App.Instance.Dispatcher.Invoke(App.Instance.Shutdown);
  475. }
  476. /// <summary>
  477. /// Registers the server with administrator access.
  478. /// </summary>
  479. private void RegisterServerWithAdministratorAccess()
  480. {
  481. Logger.Info("Requesting administrative access to authorize http server");
  482. // Create a temp file path to extract the bat file to
  483. var tmpFile = Path.Combine(ConfigurationManager.CommonApplicationPaths.TempDirectory, Guid.NewGuid() + ".bat");
  484. // Extract the bat file
  485. using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MediaBrowser.ServerApplication.RegisterServer.bat"))
  486. {
  487. using (var fileStream = File.Create(tmpFile))
  488. {
  489. stream.CopyTo(fileStream);
  490. }
  491. }
  492. var startInfo = new ProcessStartInfo
  493. {
  494. FileName = tmpFile,
  495. Arguments = string.Format("{0} {1} {2} {3}", ServerConfigurationManager.Configuration.HttpServerPortNumber,
  496. HttpServerUrlPrefix,
  497. UdpServerPort,
  498. ServerConfigurationManager.Configuration.LegacyWebSocketPortNumber),
  499. CreateNoWindow = true,
  500. WindowStyle = ProcessWindowStyle.Hidden,
  501. Verb = "runas",
  502. ErrorDialog = false
  503. };
  504. using (var process = Process.Start(startInfo))
  505. {
  506. process.WaitForExit();
  507. }
  508. }
  509. }
  510. }