Skip to main content

Command Palette

Search for a command to run...

Solution for "The system cannot find the file specified" error when connecting to VPN on Windows

Published
1 min read
Solution for "The system cannot find the file specified" error when connecting to VPN on Windows
O

I work as System Administrator for more than 15 years now and I love to make my life easier by automating work & personal stuff via PowerShell (even silly things like food recipes list generation).

All credit goes to MrModaeus and his answer on Reddit

This post is intended to hopefully make it more discoverable in Google searches for anyone else with the same problem.

Long story short the error "The system cannot find the file specified" when trying to connect to VPN is caused by a corrupt or missing registry.

Just run code bellow in administrator PowerShell console to fix this:

# Create missing registry key
New-Item -Path HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters -Name DnsPolicyConfig

# Configure permissions on key for "NT Authority\DNSCache"
$keyPath = 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig'
$acl = Get-Acl -Path $keyPath

$idRef = [System.Security.Principal.NTAccount]("NT SERVICE\Dnscache")
$regRights = [System.Security.AccessControl.RegistryRights]::FullControl
$inhFlags = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit
$prFlags = [System.Security.AccessControl.PropagationFlags]::None
$acType = [System.Security.AccessControl.AccessControlType]::Allow
$rule = New-Object System.Security.AccessControl.RegistryAccessRule ($idRef, $regRights, $inhFlags, $prFlags, $acType)

$acl.AddAccessRule($rule)
$acl.SetAccessRule($rule)
$acl | Set-Acl -Path $keyPath

In case 'HKLM:\SYSTEM\CurrentControlSet\Services\Dnscache\Parameters\DnsPolicyConfig' already exists and fix didn't help, try to export it (just in case), delete it and ruh the PS code again.

More from this blog

D

Do it PowerShell way :)

78 posts

With over 15 years of experience as a system administrator, I have a passion for automating workflows using PowerShell. I believe in sharing my creations with the community. Why not, right? :)