Skip to content

Instantly share code, notes, and snippets.

@rkrx
Last active September 9, 2020 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkrx/13f6893c3c7a3cd296d241baa59859da to your computer and use it in GitHub Desktop.
Save rkrx/13f6893c3c7a3cd296d241baa59859da to your computer and use it in GitHub Desktop.
MSAccess: Add a Path to "trusted locations" and disable query confirmations for all access versions
Function Configure-Access-Settings($AccessDatabasePath) {
@('HKEY_CURRENT_USER\SOFTWARE\Microsoft', 'HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft') | Foreach-Object {
$BaseItem = $_
try {
Get-Item -Path Registry::$BaseItem\Office\* -ErrorAction Stop | ?{ $_.Name -match "\d+\.\d+$" } | Foreach-Object {
$ItemPath = $_.Name
try {
# Disable msaccess query confirmations
Get-Item -Path Registry::$ItemPath\Access\Settings -ErrorAction Stop | Out-Null
Set-ItemProperty -Path Registry::"$ItemPath\Access\Settings" -Name "Confirm Document Deletions" -Value 0
Set-ItemProperty -Path Registry::"$ItemPath\Access\Settings" -Name "Confirm Action Queries" -Value 0
Set-ItemProperty -Path Registry::"$ItemPath\Access\Settings" -Name "Confirm Record Changes" -Value 0
Set-ItemProperty -Path Registry::"$ItemPath\Access\Security" -Name "Level" -Value 1
# Add to trusted locations
$Locations = @(Get-Item -Path Registry::"$ItemPath\Access\Security\Trusted Locations\*" -ErrorAction Stop | Where-Object { "$((Get-ItemProperty -Path Registry::$($_.Name)).Path)" -like $AccessDatabasePath })
if($Locations.Count -lt 1) {
for ($NextId = 0; $NextId -lt 1000; $NextId++) {
try {
Get-Item -Path Registry::"$ItemPath\Access\Security\Trusted Locations\Location$NextId" -ErrorAction Stop | Out-Null
} catch { break }
}
$Key = "$ItemPath\Access\Security\Trusted Locations\Location$NextId"
New-Item -Path Registry::$Key | Out-Null
Set-ItemProperty -Path Registry::$Key -Name "AllowSubfolders" -Value 1 | Out-Null
Set-ItemProperty -Path Registry::$Key -Name "Date" -Value New-Date | Out-Null
Set-ItemProperty -Path Registry::$Key -Name "Description" -Value "Powershell" | Out-Null
Set-ItemProperty -Path Registry::$Key -Name "Path" -Value $AccessDatabasePath | Out-Null
}
} catch {}
}
} catch {}
}
}
Configure-Access-Settings("C:\temp\")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment