Option Explicit
Const strSecurity2003 = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Access\security\Level"
Const strSecurityEXCEL2003 = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Security\Level"
Const strSecurity = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\security\VBAWarnings"
Const strSecurityJet = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\SandBoxMode"
Const strSecurityEXCEL = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security\VBAWarnings"
Const strAccessPathRegKey2003 = "HKLM\Software\Microsoft\Office\11.0\Access\InstallRoot\Path"
Const strAccessPathRegKey = "HKLM\Software\Microsoft\Office\12.0\Access\InstallRoot\Path"
DIM strVersionAccessSetup
DIM AccessShell, strPathToAccess
DIM strCurrentPath, strNameFile
DIM WshShell, FSO
On Error Resume Next
Set WshShell = CreateObject("WScript.Shell")
' ========== Получим путь к MSACCESS.EXE ===========
Set FSO = CreateObject("Scripting.FileSystemObject")
strVersionAccessSetup = ""
'2003
strPathToAccess = WshShell.RegRead(strAccessPathRegKey2003)
if err.number = 0 then
IF (FSO.FileExists(strPathToAccess & "MSACCESS.exe" )) = TRUE Then
strVersionAccessSetup = "2003"
End If
End If
Err.Clear
'2007
If Len(strVersionAccessSetup) = 0 then
strPathToAccess = WshShell.RegRead(strAccessPathRegKey)
if err.number = 0 then
IF (FSO.FileExists(strPathToAccess & "MSACCESS.exe" )) = TRUE Then
strVersionAccessSetup = "2007"
End If
End If
End If
Err.Clear
' ========== Настроим безопасность в зависимости от версии Access ===========
If Len(strVersionAccessSetup) = 0 then
MsgBox "MS Access на машине не найден."
Else
strCurrentPath = Replace(WScript.ScriptFullName, WScript.ScriptName,"")
IF (FSO.FileExists(strCurrentPath & "Offer.accde" )) = TRUE Then
strNameFile = strCurrentPath & "Offer.accde"
ElseIf (FSO.FileExists(strCurrentPath & "Offer.mde" )) = TRUE Then
strNameFile = strCurrentPath & "Offer.mde"
End If
If WSHShell.RegRead(strSecurityJet) <> 2 Then
WSHShell.RegWrite strSecurityJet, 2, "REG_DWORD"
End If
'2007
If strVersionAccessSetup = "2007" then
'Понижаем безопасность
If WSHShell.RegRead(strSecurity) <> 1 Then
WSHShell.RegWrite strSecurity, 1, "REG_DWORD"
End If
If WSHShell.RegRead(strSecurityEXCEL) <> 1 Then
WSHShell.RegWrite strSecurityEXCEL, 1, "REG_DWORD"
End If
If Err.Number <> 0 Then
Err.Clear
WSHShell.RegWrite strSecurityEXCEL, "", "REG_DWORD"
WSHShell.RegWrite strSecurityEXCEL, 1, "REG_DWORD"
End If
If WSHShell.RegRead(strSecurityEXCEL2003) <> 1 Then
WSHShell.RegWrite strSecurityEXCEL2003, 1, "REG_DWORD"
End If
If Err.Number <> 0 Then
Err.Clear
WSHShell.RegWrite strSecurityEXCEL2003, "", "REG_DWORD"
WSHShell.RegWrite strSecurityEXCEL2003, 1, "REG_DWORD"
End If
End if
'2003
If strVersionAccessSetup = "2003" then
'Понижаем безопасность
If WSHShell.RegRead(strSecurity2003) <> 1 Then
WSHShell.RegWrite strSecurity2003, 1, "REG_DWORD"
End If
If WSHShell.RegRead(strSecurityEXCEL2003) <> 1 Then
WSHShell.RegWrite strSecurityEXCEL2003, 1, "REG_DWORD"
End If
If Err.Number <> 0 Then
Err.Clear
WSHShell.RegWrite strSecurityEXCEL2003, "", "REG_DWORD"
WSHShell.RegWrite strSecurityEXCEL2003, 1, "REG_DWORD"
End If
End if
'=========== Запустим калькулятор ================
Set AccessShell = WshShell.Exec(strPathToAccess & "MSACCESS.exe """ & strNameFile & """" & " /cmd ""Salon""")
Err.Clear
AccessShell.visible = true
WshShell.AppActivate("Предварительный расчет")
End if
Set AccessShell = nothing
Set WshShell = Nothing
Set FSO = Nothing
|