FileSystemObject.CopyFile: Permission Denied

T

TomT

MS Access 2003, running on Vista Ultimate sp1

I'm trying to simply copy a file from one location to another, and get a
runtime error 70: Permission Denied. The permissions for the file are set for
full control for all users.

Here is the sub:

Public Sub CopyFile()

Dim fs As Object
Dim isthere As Boolean

Set fs = CreateObject("Scripting.FileSystemObject")
isthere = fs.FileExists("c:\Database\Accounting\UpdateAssetMaster.bat")

If isthere = True Then

fs.CopyFile "c:\Database\Accounting\UpdateAssetMaster.bat",
"c:\database"

End If

End Sub

I can't seem to get this to work, any suggestions would be appreciated.
 
D

Dirk Goldgar

TomT said:
MS Access 2003, running on Vista Ultimate sp1

I'm trying to simply copy a file from one location to another, and get a
runtime error 70: Permission Denied. The permissions for the file are set
for
full control for all users.

Here is the sub:

Public Sub CopyFile()

Dim fs As Object
Dim isthere As Boolean

Set fs = CreateObject("Scripting.FileSystemObject")
isthere = fs.FileExists("c:\Database\Accounting\UpdateAssetMaster.bat")

If isthere = True Then

fs.CopyFile "c:\Database\Accounting\UpdateAssetMaster.bat",
"c:\database"

End If

End Sub

I can't seem to get this to work, any suggestions would be appreciated.


Do you have write permissions on the C:\Database folder?
 
M

Matthias Klaey

TomT said:
MS Access 2003, running on Vista Ultimate sp1

I'm trying to simply copy a file from one location to another, and get a
runtime error 70: Permission Denied. The permissions for the file are set for
full control for all users.
[...]>
fs.CopyFile "c:\Database\Accounting\UpdateAssetMaster.bat",
"c:\database"
[...]

I have had similar problems in Vista SP1 with the VBA FileCopy
statement.

I now use an API call:

Public Declare Function CopyFile Lib "Kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

Call CopyFile("C:\Old\myfile.bat", "C:\New\Myfile.bat", False)

This works for me without the permission error.
Notice that CopyFile returns 0 *in case of an error*, so I actually
use something like

If CopyFile(...) <> 0 Then
... ok
Else
Call MsgBox("CopyFile failed")
End If

HTH
Matthias Kläy
 
P

Peter Yang[MSFT]

Hello,

You may also want to run as administrator to test the stiatuion, right
click on the icon, select Properties -> Compatibility and enable the “Run
this program as an administrator”
checkbox. Click on Apply and then Ok.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support


=====================================================

When responding to posts, please "Reply to Group" via your
newsreader so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TomT

Thanks Matthias - I had a feeling it was Vista related. I'm going to run a
test on a different OS.

Matthias Klaey said:
TomT said:
MS Access 2003, running on Vista Ultimate sp1

I'm trying to simply copy a file from one location to another, and get a
runtime error 70: Permission Denied. The permissions for the file are set for
full control for all users.
[...]>
fs.CopyFile "c:\Database\Accounting\UpdateAssetMaster.bat",
"c:\database"
[...]

I have had similar problems in Vista SP1 with the VBA FileCopy
statement.

I now use an API call:

Public Declare Function CopyFile Lib "Kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

Call CopyFile("C:\Old\myfile.bat", "C:\New\Myfile.bat", False)

This works for me without the permission error.
Notice that CopyFile returns 0 *in case of an error*, so I actually
use something like

If CopyFile(...) <> 0 Then
... ok
Else
Call MsgBox("CopyFile failed")
End If

HTH
Matthias Kläy
 
P

Peter Yang[MSFT]

Hello,

Please check if the issue occurs if the destination folder is empty or a
new folder? You may want to check if you encounter the following known
issue:

941190 Permission Denied error returned when FileSystemObject.CopyFolder
encounters a Read-Only Destination File
http://support.microsoft.com/default.aspx?scid=kb;EN-US;941190

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support


=====================================================

When responding to posts, please "Reply to Group" via your
newsreader so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TomT

I created a new folder, test. It's read only flag is set, and tho I can
un=check it, it doesn't stick. I have full permissions on the folder. I tried
the following via a command prompt:

attrib -r +s c:\test

It did not appear to make any difference. The process still fails to copy a
file, with the same error.

Thanks
 
P

Peter Yang[MSFT]

Hello,

Based on my test, this issue occurs because the destination file name is
not completed. Please try the following code to see if it works for you:

Public Sub CopyFile()

Dim fs As Object
Dim isthere As Boolean

Set fs = CreateObject("Scripting.FileSystemObject")
isthere = fs.FileExists("c:\Database\Accounting\UpdateAssetMaster.bat")

If isthere = True Then

fs.CopyFile "c:\Database\Accounting\UpdateAssetMaster.bat",
"c:\database\UpdateAssetMaster.bat"

End If

End Sub

If you encounter any problem, please feel free to let's know. Thank you.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support


=====================================================

When responding to posts, please "Reply to Group" via your
newsreader so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Yang[MSFT]

My pleasure!

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support


=====================================================

When responding to posts, please "Reply to Group" via your
newsreader so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
T

TomT

Peter, a quick follow: one system returned this error when running code
calling the FileSystemObject:

Automation Error
Library Not Registered

Would this be the Windows Script Host ocx (wshom.ocx), or something else?

Thanks
 
P

Peter Yang[MSFT]

Hello Tom,

This issue can he caused by missing references or extraneous references
that are not needed in the application. You may want to check references in
code window.

If the issue persists, you may want to refer to the following article to
troubleshoot the issue:

http://support.microsoft.com/kb/274038/en-us

If you have further questions, please feel free to let's know.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support


=====================================================

When responding to posts, please "Reply to Group" via your
newsreader so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Yang[MSFT]

Hello Tom,

Great to hear you solved the issue!

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support


=====================================================

When responding to posts, please "Reply to Group" via your
newsreader so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Joined
Jun 29, 2012
Messages
1
Reaction score
0
Thank you so much "Peter Yang" for your valuable suggestion and resolution to this post. I have encountered this issue previously also and was unable to find any resolution...Moreover, most of the time users (including me) thinks that they are using correct syntax for .copyfile/copyfolder methos provided by FileSystemObject and focus of their troubleshooting narrows down to the OS files/folder permissions.

Thanks once again for this resolution.:thumb:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top