Is there a way to flush the DNS cache from a C# WPF app? The application would be running on either XP, Vista, or Windows 7.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You can use a function from Microsoft's "dnsapi.dll". This will allow you to do this completely programmatically:
I have tested this and it works great.
This may be the poor-man's solution, but you could use
System.Diagnostics.Process
to launchipconfig /flushdns
.I searched on the internet and couldnt find away to flush a single dns entry. Working on something for failing over to backup datacenter this is needed for me. I dissembled the DnsFlushResolverCacheEntry_W and came up with the p/invoke sig below. I use the DnsQuery method with the QueryNoWireFlag and NoHostFile flag. If there are any results then I call DnsFlushResolverCacheEntry_W. This might be good info for someone in the future looking to do the same
Try this -