Const SystemFolder= 1
Dim fso  'to be used for file related code
Dim SysFolder
Dim SysFolderPath
Dim strAppData 
Dim strUserProfile
Dim RegEdPath
Dim strAppFolder
Dim strAppName
Dim bitness
Dim MSAccPath
Dim RegKey
Set WshShell = WScript.CreateObject("WScript.Shell")
RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\" _
    & "CurrentVersion\App Paths\MSACCESS.EXE\Path"
MSAccPath = WshShell.RegRead(RegKey)

strAppName = "LASERS"

On Error Resume Next
Set Office= CreateObject("Access.Application")
Set Office= CreateObject("Word.Application")
If Mid(Office.ProductCode(),21,1)="1" Then
	bitness = "x64"
Else
	bitness = "x86"
End if
If Err.number<>0 then
   MsgBox "Warning: The Access Runtime might not be installed.", vbExclamation, "LASERS Client Install"
wscript.quit
end if
On Error goto 0

Set fso = wscript.CreateObject("Scripting.FileSystemObject")
Set SysFolder =fso.GetSpecialFolder(SystemFolder)
SysFolderPath= SysFolder.Path

'initialize the script shell object

strAppData = WshShell.ExpandEnvironmentStrings("%APPDATA%") 
strAppFolder = strAppData & "\" & strAppName

strUserProfile = WshShell.ExpandEnvironmentStrings("%USERPROFILE%") 

'Create shortcuts in desktop and start menu
sLinkFile = strUserProfile & "\Desktop\LASERS.lnk" 
Set oLink = WshShell.CreateShortcut(sLinkFile) 
oLink.IconLocation = strAppFolder & "\Resources\LASERS_icon.ico"
oLink.TargetPath = MSAccPath & "MSACCESS.EXE"
oLink.Arguments = "/runtime """ & strAppFolder & "\LASERS_client_" & bitness & ".accdr"""
oLink.Save

sLinkFile = strAppData & "\Microsoft\Windows\Start Menu\Programs\LASERS\LASERS.lnk" 
Set oLink = WshShell.CreateShortcut(sLinkFile) 
oLink.IconLocation = strAppFolder & "\Resources\LASERS_icon.ico" 
oLink.TargetPath = MSAccPath & "MSACCESS.EXE"
oLink.Arguments = "/runtime """ & strAppFolder & "\LASERS_client_" & bitness & ".accdr"""
oLink.Save

'Office 12
RegEdPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\"
WshShell.RegWrite  RegEdPath  ,strAppName
'Write the values into the registry
WshShell.RegWrite  RegEdPath & strAppName & "\Path" , strAppFolder & "\"
WshShell.RegWrite  RegEdPath & strAppName & "\AllowSubfolders" , 1, "REG_DWORD"

'Office 14
RegEdPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\"
WshShell.RegWrite  RegEdPath  ,strAppName
'Write the values into the registry
WshShell.RegWrite  RegEdPath & strAppName & "\Path" , strAppFolder & "\"
WshShell.RegWrite  RegEdPath & strAppName & "\AllowSubfolders" , 1, "REG_DWORD"

'Office 15
RegEdPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\"
WshShell.RegWrite  RegEdPath  ,strAppName
'Write the values into the registry
WshShell.RegWrite  RegEdPath & strAppName & "\Path" , strAppFolder & "\"
WshShell.RegWrite  RegEdPath & strAppName & "\AllowSubfolders" , 1, "REG_DWORD"

'Office 16
RegEdPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Access\Security\Trusted Locations\"
WshShell.RegWrite  RegEdPath  ,strAppName
'Write the values into the registry
WshShell.RegWrite  RegEdPath & strAppName & "\Path" , strAppFolder & "\"
WshShell.RegWrite  RegEdPath & strAppName & "\AllowSubfolders" , 1, "REG_DWORD"

MsgBox "The software has been successfully installed.", vbInformation, "Install LASERS Client"

wscript.Quit
