File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -22,18 +22,33 @@ protected override ContextMenuStrip CreateMenu()
22
22
ContextMenuStrip menuStrip = new ContextMenuStrip ( ) ;
23
23
24
24
ToolStripMenuItem menuItem = new ToolStripMenuItem ( ) { Text = "Open in Command prompt" } ;
25
- menuItem . Click += OnClicked ;
25
+
26
+ ToolStripMenuItem runAsUserItem = new ToolStripMenuItem ( ) { Text = "As Current User" } ,
27
+ runAsAdmin = new ToolStripMenuItem ( ) { Text = "As Administrator" } ;
28
+
29
+ runAsUserItem . Click += ( s , e ) => { RunCMD ( false ) ; } ;
30
+ runAsAdmin . Click += ( s , e ) => { RunCMD ( true ) ; } ;
31
+
32
+ menuItem . DropDownItems . AddRange ( new ToolStripItem [ ] { runAsUserItem , runAsAdmin } ) ;
26
33
27
34
menuStrip . Items . Add ( menuItem ) ;
28
35
return menuStrip ;
29
36
}
30
37
31
- private void OnClicked ( object sender , EventArgs e )
38
+ private void RunCMD ( bool asadmin )
32
39
{
33
40
Process cmd = new Process ( ) ;
34
-
35
41
cmd . StartInfo . FileName = "cmd.exe" ;
36
- cmd . StartInfo . WorkingDirectory = FolderPath ;
42
+
43
+ if ( asadmin )
44
+ {
45
+ cmd . StartInfo . UseShellExecute = true ;
46
+ cmd . StartInfo . Arguments = $ "/k cd /d \" { FolderPath } \" ";
47
+ cmd . StartInfo . Verb = "runas" ;
48
+ }
49
+ else {
50
+ cmd . StartInfo . WorkingDirectory = FolderPath ;
51
+ }
37
52
38
53
cmd . Start ( ) ;
39
54
}
You can’t perform that action at this time.
0 commit comments