File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed
Plugins/Wox.Plugin.Folder Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 22using System . Collections . Generic ;
33using System . Diagnostics ;
44using System . IO ;
5+ using System . Threading . Tasks ;
56using System . Windows ;
67using Wox . Infrastructure . Logger ;
8+ using Wox . Plugin . SharedCommands ;
79
810namespace Wox . Plugin . Folder
911{
@@ -100,6 +102,27 @@ public List<Result> LoadContextMenus(Result selectedResult)
100102 IcoPath = icoPath
101103 } ) ;
102104
105+ if ( record . Type == ResultType . File && CanRunAsDifferentUser ( record . FullPath ) )
106+ contextMenus . Add ( new Result
107+ {
108+ Title = "Run as different user" ,
109+ Action = ( context ) =>
110+ {
111+ try
112+ {
113+ Task . Run ( ( ) => ShellCommand . RunAsDifferentUser ( record . FullPath . SetProcessStartInfo ( ) ) ) ;
114+ }
115+ catch ( FileNotFoundException e )
116+ {
117+ var name = "Plugin: Folder" ;
118+ var message = $ "File not found: { e . Message } ";
119+ _context . API . ShowMsg ( name , message ) ;
120+ }
121+
122+ return true ;
123+ } ,
124+ IcoPath = "Images/user.png"
125+ } ) ;
103126 }
104127
105128 return contextMenus ;
@@ -162,6 +185,20 @@ public void LogException(string message, Exception e)
162185 {
163186 Log . Exception ( $ "|Wox.Plugin.Folder.ContextMenu|{ message } ", e ) ;
164187 }
188+
189+ private bool CanRunAsDifferentUser ( string path )
190+ {
191+ switch ( Path . GetExtension ( path ) )
192+ {
193+ case ".exe" :
194+ case ".bat" :
195+ return true ;
196+
197+ default :
198+ return false ;
199+
200+ }
201+ }
165202 }
166203
167204 public class SearchResult
Original file line number Diff line number Diff line change 8484 <Content Include =" Images\file.png" >
8585 <CopyToOutputDirectory >PreserveNewest</CopyToOutputDirectory >
8686 </Content >
87+ <None Include =" Images\user.png" >
88+ <CopyToOutputDirectory >Always</CopyToOutputDirectory >
89+ </None >
8790 <Content Include =" Languages\en.xaml" >
8891 <Generator >MSBuild:Compile</Generator >
8992 <SubType >Designer</SubType >
You can’t perform that action at this time.
0 commit comments