Solved Permission denied to copy

gstylianou

Registered User.
Local time
Today, 16:49
Joined
Dec 16, 2013
Messages
359
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
 
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.
 
Is this a stand-alone personal PC or part of an organization network?
 
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.
 
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.
 
maybe you need to TakeOwner-ship of ToFolder first before you can use the code.
 
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:
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

Back
Top Bottom