/// </returns>
public static IEnumerable<int> GetPublishedProcesses()
{
- static IEnumerable<int> GetAllPublishedProcesses()
+ static IEnumerable<int> GetAllPublishedProcesses(string[] files)
{
- foreach (var port in Directory.GetFiles(PidIpcEndpoint.IpcRootPath))
+ foreach (var port in files)
{
var fileName = new FileInfo(port).Name;
var match = Regex.Match(fileName, PidIpcEndpoint.DiagnosticsPortPattern);
yield return processId;
}
}
-
- return GetAllPublishedProcesses().Distinct();
+ try
+ {
+ string[] files = Directory.GetFiles(PidIpcEndpoint.IpcRootPath);
+ return GetAllPublishedProcesses(files).Distinct();
+ }
+ catch ( UnauthorizedAccessException ex)
+ {
+ if (PidIpcEndpoint.IpcRootPath.StartsWith(@"\\.\pipe"))
+ {
+ throw new DiagnosticsClientException($"Enumerating {PidIpcEndpoint.IpcRootPath} is not authorized", ex);
+ }
+ else
+ {
+ throw;
+ }
+ }
}
internal ProcessInfo GetProcessInfo()
public class DiagnosticsClientException : Exception
{
public DiagnosticsClientException(string msg) : base(msg) {}
+ public DiagnosticsClientException(string msg, Exception exception) : base(msg, exception) {}
}
// When a certian command is not supported by either the library or the target process' runtime
String cmdLineArgs = GetArgs(process);
cmdLineArgs = cmdLineArgs == process.MainModule?.FileName ? string.Empty : cmdLineArgs;
string fileName = process.MainModule?.FileName ?? string.Empty;
-
var commandInfo = new ProcessDetails()
{
ProcessId = process.Id,
FormatTableRows(printInfo, sb);
console.Out.WriteLine(sb.ToString());
}
- catch (InvalidOperationException ex)
+ catch (Exception ex)
{
console.Out.WriteLine(ex.ToString());
}