Windows 7 and Vista deny access to C Drive Root

If you are running a custom MS Access application that, for example, writes a batch file to the root of the C drive in order to perform an update or a compact, then you will have noticed that this no longer works with Windows 7, 8 or Vista. This is because the new Windows system does not allow applications to access these special areas anymore.

What you need to do is either explicitly allow permissions here (duh) or modify the applications code to write to your profile area e.g. c:\users\steve. You can use the variable Environ(“USERNAME”) to point it off to the appropriate user’s location.

Public Function UserNameWindows() As String
UserNameWindows = Environ(“USERNAME”)
End Function

So your UpdateDB.bat file might now look like this:

Public Function UpdateDB()
On Error Resume Next ‘Error Handling
Dim nFile As Long
strBack = GetDBPath
strFront = CurrentDb.Name
pos = InStrRev(strFront, “\”)
strFrontFile = Right(strFront, Len(strFront) – pos)
strFrontPath = Left(strFront, pos)
pos = InStrRev(strBack, “\”)
strBackFile = Right(strBack, Len(strBack) – pos)
strBackPath = Left(strBack, pos)
UpdateDB = “C:\Users\” & UserNameWindows & “\updatedb.bat”
AC = Chr$(34)
LockFile = (Left(strFront, Len(strFront) – 3) & “ldb”)
If Dir(UpdateDB) <> “” Then Kill UpdateDB
nFile = FreeFile
Open UpdateDB For Append As nFile
Print #nFile, “Echo Off”
Print #nFile, “:Loop”
Print #nFile, “If Exist ” & AC & LockFile & AC & ” Goto Loop”
Print #nFile, “Copy ” & AC & strBackPath & strFrontFile & AC & ” ” & AC & strFront & AC
‘Print #nFile, “:Complete”
‘Print #nFile, “If Exist ” & AC & LockFile & AC & ” Goto Complete”
Print #nFile, “” & AC & “C:\Program Files\Microsoft Office\Office\MSACCESS.EXE ” & AC & ” ” & AC & strFront & AC
Print #nFile, “” & AC & “C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE ” & AC & ” ” & AC & strFront & AC
Print #nFile, “” & AC & “C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE ” & AC & ” ” & AC & strFront & AC
Print #nFile, “exit”
Close nFile
Shell UpdateDB
DoCmd.Quit
Exit Function
ErrH:
Call ErrorLog(Err.Number, Err.Description, Me_Form.Name, “Form_Load_Routine”)
Resume Next
End Function

and your Compact routine might now look like this:

Public Function Compact_RoutineBE()
On Error Resume Next ‘Error Handling
Dim strSource As String
Dim LockFile As String
Dim nFile As Long
Dim AC As String
strSource = GetDBPath
strFront = CurrentDb.Name
Compact_RoutineBE = “C:\Users\” & UserNameWindows & “\selfcomp.bat”
AC = Chr$(34)
LockFile = (Left(strSource, Len(strSource) – 3) & “ldb”)
If Dir(Compact_RoutineBE) <> “” Then Kill Compact_RoutineBE
nFile = FreeFile
Open Compact_RoutineBE For Append As nFile
Print #nFile, “Echo Off”
Print #nFile, “:Loop”
Print #nFile, “If Exist ” & AC & LockFile & AC & ” Goto Loop”
‘Print #nFile, “Copy ” & AC & CurrentDb.Name & AC & ” ” & AC & (Left(CurrentDb.Name, Len(CurrentDb.Name) – 3) & “Old” & AC)
Print #nFile, AC & “C:\Program Files\Microsoft Office\Office\MSACCESS.EXE” & AC & ” ” & AC & strSource & AC & ” /compact”
Print #nFile, AC & “C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE” & AC & ” ” & AC & strSource & AC & ” /compact”
Print #nFile, AC & “C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE” & AC & ” ” & AC & strSource & AC & ” /compact”
‘Print #nFile, “:Complete”
‘Print #nFile, “If Exist ” & AC & LockFile & AC & ” Goto Complete”
Print #nFile, “” & AC & “C:\Program Files\Microsoft Office\Office\MSACCESS.EXE ” & AC & ” ” & AC & strFront & AC
Print #nFile, “” & AC & “C:\Program Files\Microsoft Office\Office11\MSACCESS.EXE ” & AC & ” ” & AC & strFront & AC
Print #nFile, “” & AC & “C:\Program Files\Microsoft Office\Office12\MSACCESS.EXE ” & AC & ” ” & AC & strFront & AC
‘Print #nFile, “del ” & AC & Compact_RoutineBE & AC
Print #nFile, “exit”
Close nFile
Shell Compact_RoutineBE
DoCmd.Quit
Exit Function
ErrH:
Call ErrorLog(Err.Number, Err.Description, Me_Form.Name, “Form_Load_Routine”)
Resume Next
End Function