diff --git a/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs b/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs index 92fae4620..05e47dd52 100644 --- a/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs +++ b/Plugins/Wox.Plugin.Folder/ContextMenuLoader.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Threading.Tasks; using System.Windows; using Wox.Infrastructure.Logger; +using Wox.Plugin.SharedCommands; namespace Wox.Plugin.Folder { @@ -100,6 +102,27 @@ public List LoadContextMenus(Result selectedResult) IcoPath = icoPath }); + if (record.Type == ResultType.File && CanRunAsDifferentUser(record.FullPath)) + contextMenus.Add(new Result + { + Title = "Run as different user", + Action = (context) => + { + try + { + Task.Run(()=> ShellCommand.RunAsDifferentUser(record.FullPath.SetProcessStartInfo())); + } + catch (FileNotFoundException e) + { + var name = "Plugin: Folder"; + var message = $"File not found: {e.Message}"; + _context.API.ShowMsg(name, message); + } + + return true; + }, + IcoPath = "Images/user.png" + }); } return contextMenus; @@ -162,6 +185,20 @@ public void LogException(string message, Exception e) { Log.Exception($"|Wox.Plugin.Folder.ContextMenu|{message}", e); } + + private bool CanRunAsDifferentUser(string path) + { + switch(Path.GetExtension(path)) + { + case ".exe": + case ".bat": + return true; + + default: + return false; + + } + } } public class SearchResult diff --git a/Plugins/Wox.Plugin.Folder/Images/user.png b/Plugins/Wox.Plugin.Folder/Images/user.png new file mode 100644 index 000000000..2d45c1ee9 Binary files /dev/null and b/Plugins/Wox.Plugin.Folder/Images/user.png differ diff --git a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj index e0305a648..daccbbf88 100644 --- a/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj +++ b/Plugins/Wox.Plugin.Folder/Wox.Plugin.Folder.csproj @@ -84,6 +84,9 @@ PreserveNewest + + Always + MSBuild:Compile Designer