Improve error message in ListDNSCache() when using Windows before 8/2012
The 'MSFT_DNSClientCache' WMI class is unavailable on older Windows versions Cf. https://msdn.microsoft.com/en-us/library/hh872334%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396master
parent
73fcff8e9c
commit
f12f301c82
|
@ -4008,15 +4008,14 @@ namespace Seatbelt
|
||||||
|
|
||||||
public static void ListDNSCache()
|
public static void ListDNSCache()
|
||||||
{
|
{
|
||||||
// lists the local DNS cache via WMI (MSFT_DNSClientCache class)
|
Console.WriteLine("\r\n\r\n=== DNS Cache (via WMI) ===\r\n");
|
||||||
|
|
||||||
|
// lists the local DNS cache via WMI (MSFT_DNSClientCache class)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ManagementObjectSearcher wmiData = new ManagementObjectSearcher(@"root\standardcimv2", "SELECT * FROM MSFT_DNSClientCache");
|
ManagementObjectSearcher wmiData = new ManagementObjectSearcher(@"root\standardcimv2", "SELECT * FROM MSFT_DNSClientCache");
|
||||||
ManagementObjectCollection data = wmiData.Get();
|
ManagementObjectCollection data = wmiData.Get();
|
||||||
|
|
||||||
Console.WriteLine("\r\n\r\n=== DNS Cache (via WMI) ===\r\n");
|
|
||||||
|
|
||||||
foreach (ManagementObject result in data)
|
foreach (ManagementObject result in data)
|
||||||
{
|
{
|
||||||
Console.WriteLine(" Entry : {0}", result["Entry"]);
|
Console.WriteLine(" Entry : {0}", result["Entry"]);
|
||||||
|
@ -4024,6 +4023,10 @@ namespace Seatbelt
|
||||||
Console.WriteLine(" Data : {0}\r\n", result["Data"]);
|
Console.WriteLine(" Data : {0}\r\n", result["Data"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (ManagementException ex) when (ex.ErrorCode == ManagementStatus.InvalidNamespace)
|
||||||
|
{
|
||||||
|
Console.WriteLine(" [X] 'MSFT_DNSClientCache' WMI class unavailable (minimum supported versions of Windows: 8/2012)", ex.Message);
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine(" [X] Exception: {0}", ex.Message);
|
Console.WriteLine(" [X] Exception: {0}", ex.Message);
|
||||||
|
|
Loading…
Reference in New Issue