File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using System . Numerics ;
4+ using System . Security . Principal ;
45using System . Threading ;
56using System . Threading . Tasks ;
67
@@ -62,7 +63,13 @@ public void New(Action action)
6263 // okay, let's add the thing
6364 proceed = true ;
6465
65- _taskFactory . StartNew ( action , _cancellationSource . Token ) ;
66+ WindowsIdentity impersonatedUser = WindowsIdentity . GetCurrent ( ) ;
67+ _taskFactory . StartNew ( ( ) => {
68+ using ( WindowsImpersonationContext ctx = impersonatedUser . Impersonate ( ) )
69+ {
70+ action ( ) ;
71+ }
72+ } , _cancellationSource . Token ) ;
6673 }
6774 }
6875 }
Original file line number Diff line number Diff line change 1- using NLog ;
1+ using NLog ;
22using NLog . Config ;
33using NLog . Layouts ;
44using NLog . Targets ;
88using System ;
99using System . Diagnostics ;
1010using System . IO ;
11- using System . Threading . Tasks ;
11+ using System . Security . Principal ;
1212using System . Text . RegularExpressions ;
1313using System . Threading ;
14+ using System . Threading . Tasks ;
1415
1516namespace Snaffler
1617{
@@ -201,7 +202,14 @@ public void Run(string[] args)
201202
202203 var tokenSource = new CancellationTokenSource ( ) ;
203204 var token = tokenSource . Token ;
204- Task thing = Task . Factory . StartNew ( ( ) => { controller . Execute ( ) ; } , token ) ;
205+
206+ WindowsIdentity impersonatedUser = WindowsIdentity . GetCurrent ( ) ;
207+ Task thing = Task . Factory . StartNew ( ( ) => {
208+ using ( WindowsImpersonationContext ctx = impersonatedUser . Impersonate ( ) )
209+ {
210+ controller . Execute ( ) ;
211+ }
212+ } , token ) ;
205213 bool exit = false ;
206214
207215 while ( exit == false )
You can’t perform that action at this time.
0 commit comments