Modify Access Application Options in PoSH

Share on:

I put together the following script to help a small group configure Microsoft Access during login in a kiosk environment. You're welcome to steal and modify as you see fit. For all the options you can possibly set, see this MSDN page (ignore the comment that it's for Visual Basic...)

 1<#
 2
 3*******************************************************************************************************************************
 4** All code is for demonstration only and should be used at your own risk. I cannot accept liability for unexpected results. **
 5*******************************************************************************************************************************
 6
 7Use: You're welcome to use, modify, and distribute this script.  I'd love to hear about how you're using it or modifications you've made in the comments section of the original post over at ChristopherKibble.com.
 8
 9Lot's of help from here:
10https://msdn.microsoft.com/VBA/Access-VBA/articles/set-options-from-visual-basic
11
12#>
13
14$title = "Microsoft Access Configuration"
15$access = New-Object -ComObject Access.Application
16
17# Invisible is the default, but setting here so that it can be changed for troubleshooting if necessary.
18$access.visible = $false   
19
20if(!$access) {
21    #Add-Type -AssemblyName "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
22	[void][System.Windows.Forms.MessageBox]::Show('We were unable to configure Microsoft Access at this time.', $title) # Casting the method to [void] suppresses the output. 
23}
24
25# Default Open Mode for Databases
26#      0 = Shared
27#      1 = Exclusive
28
29# Default Record Locking
30#      0 = No Locks
31#      1 = All Records
32#      2 = Edited Records
33
34try {
35	$access.SetOption("Default Open Mode for Databases", 0)
36	$access.SetOption("Default Record Locking", 2)
37	$access.SetOption("Use Row Level Locking", $true)
38} catch {
39	#Add-Type -AssemblyName "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
40	[void][System.Windows.Forms.MessageBox]::Show('There was an error setting one or more Microsoft Access Settings', $title) # Casting the method to [void] suppresses the output. 	
41}
42
43$access.Quit()


No comments