99using System . Security . Principal ;
1010using System . ServiceProcess ;
1111using Microsoft . Win32 . SafeHandles ;
12- using PSADT . AccountManagement ;
1312using PSADT . Extensions ;
1413using PSADT . FileSystem ;
1514using PSADT . LibraryInterfaces ;
@@ -182,8 +181,8 @@ static string[] GetProcessArgv(Process process, Dictionary<Process, string[]> pr
182181 NTAccount ? username = null ;
183182 if ( ! process . HasExited )
184183 {
185- // Leverage SeDebugPrivilege if we have it for complete accuracy .
186- if ( PrivilegeManager . HasPrivilege ( SE_PRIVILEGE . SeDebugPrivilege ) )
184+ // Users can only get the username for their own processes, whereas admins can get anyone's .
185+ try
187186 {
188187 // We're caching the process, so don't dispose of its SafeHande as .NET caches it also...
189188 _ = AdvApi32 . OpenProcessToken ( process . SafeHandle , TOKEN_ACCESS_MASK . TOKEN_QUERY , out SafeFileHandle hToken ) ;
@@ -192,23 +191,9 @@ static string[] GetProcessArgv(Process process, Dictionary<Process, string[]> pr
192191 username = TokenManager . GetTokenSid ( hToken ) . Translate ( typeof ( NTAccount ) ) as NTAccount ;
193192 }
194193 }
195-
196- // If we couldn't get it that way, test for session Id equality.
197- if ( username is null )
194+ catch ( Exception ex ) when ( ex . Message is not null )
198195 {
199- // This needs to be in a try/catch as accessing SessionId can throw E_ACCESSDENIED exceptions.
200- try
201- {
202- if ( process . SessionId == AccountUtilities . CallerSessionId )
203- {
204- // The process is in our session, so assume it's ours.
205- username = AccountUtilities . CallerUsername ;
206- }
207- }
208- catch ( Exception ex ) when ( ex . Message is not null )
209- {
210- username = null ;
211- }
196+ username = null ;
212197 }
213198 }
214199
0 commit comments