mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 04:07:40 +02:00
Add run as different user option when file is of certain type
This commit is contained in:
@@ -2,8 +2,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
|
using Wox.Plugin.SharedCommands;
|
||||||
|
|
||||||
namespace Wox.Plugin.Folder
|
namespace Wox.Plugin.Folder
|
||||||
{
|
{
|
||||||
@@ -100,6 +102,27 @@ namespace Wox.Plugin.Folder
|
|||||||
IcoPath = icoPath
|
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;
|
return contextMenus;
|
||||||
@@ -162,6 +185,20 @@ namespace Wox.Plugin.Folder
|
|||||||
{
|
{
|
||||||
Log.Exception($"|Wox.Plugin.Folder.ContextMenu|{message}", 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
|
public class SearchResult
|
||||||
|
|||||||
BIN
Plugins/Wox.Plugin.Folder/Images/user.png
Normal file
BIN
Plugins/Wox.Plugin.Folder/Images/user.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
@@ -84,6 +84,9 @@
|
|||||||
<Content Include="Images\file.png">
|
<Content Include="Images\file.png">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<None Include="Images\user.png">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<Content Include="Languages\en.xaml">
|
<Content Include="Languages\en.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
|||||||
Reference in New Issue
Block a user