|
14 | 14 | using System.Windows.Media; |
15 | 15 | using CommunityToolkit.Mvvm.DependencyInjection; |
16 | 16 | using Flow.Launcher.Core; |
| 17 | +using Flow.Launcher.Core.ExternalPlugins; |
17 | 18 | using Flow.Launcher.Core.Plugin; |
18 | 19 | using Flow.Launcher.Core.Resource; |
19 | | -using Flow.Launcher.Core.ExternalPlugins; |
20 | 20 | using Flow.Launcher.Core.Storage; |
21 | 21 | using Flow.Launcher.Helper; |
22 | 22 | using Flow.Launcher.Infrastructure; |
23 | | -using Flow.Launcher.Infrastructure.Http; |
24 | 23 | using Flow.Launcher.Infrastructure.Hotkey; |
| 24 | +using Flow.Launcher.Infrastructure.Http; |
25 | 25 | using Flow.Launcher.Infrastructure.Image; |
26 | 26 | using Flow.Launcher.Infrastructure.Logger; |
27 | 27 | using Flow.Launcher.Infrastructure.Storage; |
28 | 28 | using Flow.Launcher.Infrastructure.UserSettings; |
29 | 29 | using Flow.Launcher.Plugin; |
30 | | -using Flow.Launcher.Plugin.SharedModels; |
31 | 30 | using Flow.Launcher.Plugin.SharedCommands; |
| 31 | +using Flow.Launcher.Plugin.SharedModels; |
32 | 32 | using Flow.Launcher.ViewModel; |
33 | 33 | using JetBrains.Annotations; |
34 | 34 | using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch; |
@@ -577,6 +577,29 @@ public long StopwatchLogInfo(string className, string message, Action action, [C |
577 | 577 | public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") => |
578 | 578 | Stopwatch.InfoAsync(className, message, action, methodName); |
579 | 579 |
|
| 580 | + public void StartProcess(string filePath, string workingDirectory, string arguments = "", bool runAsAdmin = false) |
| 581 | + { |
| 582 | + // Deelevate process if it is running as administrator |
| 583 | + if (Win32Helper.IsAdministrator() && !runAsAdmin) |
| 584 | + { |
| 585 | + Win32Helper.RunAsDesktopUser(filePath, workingDirectory, arguments, out var errorInfo); |
| 586 | + if (!string.IsNullOrEmpty(errorInfo)) |
| 587 | + { |
| 588 | + LogError(ClassName, $"Failed to start process {filePath} with error: {errorInfo}"); |
| 589 | + } |
| 590 | + } |
| 591 | + |
| 592 | + var info = new ProcessStartInfo |
| 593 | + { |
| 594 | + FileName = filePath, |
| 595 | + WorkingDirectory = workingDirectory, |
| 596 | + Arguments = arguments, |
| 597 | + UseShellExecute = true, |
| 598 | + Verb = runAsAdmin ? "runas" : "", |
| 599 | + }; |
| 600 | + Process.Start(info)?.Dispose(); |
| 601 | + } |
| 602 | + |
580 | 603 | #endregion |
581 | 604 |
|
582 | 605 | #region Private Methods |
|
0 commit comments