PERMISSION DENIED ON .CopyFolder (1 Viewer)

yaya

Registered User.
Local time
Today, 04:26
Joined
Dec 4, 2018
Messages
18
Hello,

I have set up a function to automatically backup the scheduled task files on our computer, located at "C:\Windows\System32\Tasks\Databases"

The following code is throwing a permission denied error:
Code:
objFSO.CopyFolder "C:\Windows\System32\Tasks\Databases*", archivePath

objFSO is declared and initialized as:
Code:
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

After some googling about this issue, i have ensured that the archivePath i am passing has a trailing backslash.

I also think the permissions are fine because i am manually able to copy paste the files at C:\Windows\System32\Tasks\Databases into the archive folder fine. However, when I try to do it through code i am getting the permission denied error.

Any help with understanding/resolving this issue would be greatly appreciated!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:26
Joined
Oct 29, 2018
Messages
21,471
Hi. Without testing, I am wondering about the trailing asterisk (*) in your source path. Could you try removing it or replacing it with \*.* instead? Just curious...
 

yaya

Registered User.
Local time
Today, 04:26
Joined
Dec 4, 2018
Messages
18
Hi. Without testing, I am wondering about the trailing asterisk (*) in your source path. Could you try removing it or replacing it with \*.* instead? Just curious...

Hello DBguy,

I tried removing the asterisk and then got the same error, when I add a trailing slash to the source path i get a path not found error.

I have tested this code on another machine and it works. I cant figure out what is wrong with the permissions for the other computer because outside of access the permissions seem fine.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:26
Joined
Sep 12, 2006
Messages
15,653
what is the precise error message you get?

should it be this (as theDBGuy suggested)
objFSO.CopyFolder "C:\Windows\System32\Tasks\Databases\*.*"

rather than this, which looks wrong.
objFSO.CopyFolder "C:\Windows\System32\Tasks\Databases*"
 

Mark_

Longboard on the internet
Local time
Today, 04:26
Joined
Sep 12, 2017
Messages
2,111
Please post the command line copy that works so we can make sure you are using the proper syntax.
 

yaya

Registered User.
Local time
Today, 04:26
Joined
Dec 4, 2018
Messages
18
Thanks for the replies!

After further digging, I have discovered what was wrong as well as a solution!

The code running on the two machines was exactly the same, so I realized that the issue had to be with the one machine somewhere. Then, after verifying it wasnt a permissions issue (I could manually copy paste the files) I realized that the machine that worked was a 32 bit server and the one giving me issues was 64 bit (running 32bit MS Access).

Then, after some more googling, I discovered that "When a 32-bit process on 64-bit Windows tries to access 'C:\Windows\System32', WOW64 redirects it to 'C:\Windows\SysWOW64'."

So, the fix for this was for the 64 bit machine to copy from 'C:\Windows\SysNative' instead of 'C:\Windows\System32'.

I modified the function to check to see what type of OS its being ran from first and then copy from System32 or SysNative appropriately.

I found the following function online and implemented it into my own to do this check for me:
Code:
Public Function isWin64bit() As Boolean
  isWin64bit = 0 < Len(Environ("ProgramW6432"))
End Function

The above function implemented:
Code:
If isWin64bit Then
    objFSO.CopyFolder "C:\Windows\SysNative\Tasks\Databases*", archivePath
  Else '32 bit
    objFSO.CopyFolder "C:\Windows\System32\Tasks\Databases*", archivePath
End If

This is a .CopyFolder call not a FileCopy. The asterisk at the end of the source path is needed to be able to copy the entire folder itself as well as its contents to the destination path.

Thanks again everyone! hopefully my answer will help someone else in the future!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 04:26
Joined
Oct 29, 2018
Messages
21,471
Thanks for the replies!

After further digging, I have discovered what was wrong as well as a solution!

The code running on the two machines was exactly the same, so I realized that the issue had to be with the one machine somewhere. Then, after verifying it wasnt a permissions issue (I could manually copy paste the files) I realized that the machine that worked was a 32 bit server and the one giving me issues was 64 bit (running 32bit MS Access).

Then, after some more googling, I discovered that "When a 32-bit process on 64-bit Windows tries to access 'C:\Windows\System32', WOW64 redirects it to 'C:\Windows\SysWOW64'."

So, the fix for this was for the 64 bit machine to copy from 'C:\Windows\SysNative' instead of 'C:\Windows\System32'.

I modified the function to check to see what type of OS its being ran from first and then copy from System32 or SysNative appropriately.

I found the following function online and implemented it into my own to do this check for me:
Code:
Public Function isWin64bit() As Boolean
  isWin64bit = 0 < Len(Environ("ProgramW6432"))
End Function
The above function implemented:
Code:
If isWin64bit Then
    objFSO.CopyFolder "C:\Windows\SysNative\Tasks\Databases*", archivePath
  Else '32 bit
    objFSO.CopyFolder "C:\Windows\System32\Tasks\Databases*", archivePath
End If
This is a .CopyFolder call not a FileCopy. The asterisk at the end of the source path is needed to be able to copy the entire folder itself as well as its contents to the destination path.

Thanks again everyone! hopefully my answer will help someone else in the future!
Hi. Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom