github.com/safing/portbase@v0.19.5/utils/osdetail/dnscache_windows.go (about)

     1  package osdetail
     2  
     3  import (
     4  	"os/exec"
     5  )
     6  
     7  // EnableDNSCache enables the Windows Service "DNS Client" by setting the registry value "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dnscache" to 2 (Automatic).
     8  // A reboot is required for this setting to take effect.
     9  func EnableDNSCache() error {
    10  	return exec.Command("reg", "add", "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Dnscache", "/v", "Start", "/t", "REG_DWORD", "/d", "2", "/f").Run()
    11  }
    12  
    13  // DisableDNSCache disables the Windows Service "DNS Client" by setting the registry value "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Dnscache" to 4 (Disabled).
    14  // A reboot is required for this setting to take effect.
    15  func DisableDNSCache() error {
    16  	return exec.Command("reg", "add", "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\Dnscache", "/v", "Start", "/t", "REG_DWORD", "/d", "4", "/f").Run()
    17  }