Solved Permission denied to copy (1 Viewer)

gstylianou

Registered User.
Local time
Today, 23:22
Joined
Dec 16, 2013
Messages
357
Hi, i'm trying to copy from desktop to C:\Program Files (x86) using vba but i cannot because of the limited permission. I found the following code in a forum. Any idea?

Public Sub CopyMasterFolder()

Dim FSO As Object
Dim FromPath As String
Dim ToPath As String

FromPath = "C:\Users\User\Desktop\NutriSetup\Resources\NutriSoft"
ToPath = "C:\Program Files (x86)"

If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If

If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If

FSO.CopyFolder Source:=FromPath, Destination:=ToPath
Me.cmd2.FontBold = False
Me.cmd2.Caption = "Files copied from " & FromPath & " in " & ToPath
' MsgBox "You can find the files and subfolders from " & FromPath & " in " & ToPath

End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:22
Joined
Feb 19, 2002
Messages
43,297
If you don't have permission to update that folder, you need to talk to your support staff so they can give you permission or do it for you.
 

June7

AWF VIP
Local time
Today, 12:22
Joined
Mar 9, 2014
Messages
5,475
Is this a stand-alone personal PC or part of an organization network?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:22
Joined
Jan 20, 2009
Messages
12,852
Very odd need for a user to be copying from their Desktop to either of the Program Files folders. Such locations are restricted for very good reasons.

If you are copying an Access Application it would be better located in the users' AppData or ProgramData. where users do have permissions.
 

June7

AWF VIP
Local time
Today, 12:22
Joined
Mar 9, 2014
Messages
5,475
Have you tried manual copy/paste of file or folder into Programs folder? Should get a popup "need to provide Adminstrator permission to copy to this folder". Click Continue and action completes. I have no idea how to manage this programmatically.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:22
Joined
May 7, 2009
Messages
19,245
maybe you need to TakeOwner-ship of ToFolder first before you can use the code.
 

June7

AWF VIP
Local time
Today, 12:22
Joined
Mar 9, 2014
Messages
5,475
Try manual copy of file or folder to Program Files folder. Should get a popup "need to provide administrator permission to copy to this folder". Click Continue and action completes. I have no idea how to accomplish this programmatically. There must be some way, otherwise how could you install new programs. Seems install processes require a response to similar popup to authorize.

Why do you need to copy into Program Files folder?
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:22
Joined
Jan 20, 2009
Messages
12,852
Turning on permission for Program Files means that the user has left those folders open to attack without warning whenever they are logged in, including when online.

I'll let you contemplate that,
 

Users who are viewing this thread

Top Bottom