Permission denied on CopyFile in VBS

后端 未结 7 1173
無奈伤痛
無奈伤痛 2020-11-30 11:08

I\'m trying to automate pushing a file into my users\' home directories, but am stuck on a \"Permission Denied\" error — is thrown on line 6 here, with the CopyFile call.

相关标签:
7条回答
  • 2020-11-30 11:17

    You can do this:

    fso.CopyFile "C:\Minecraft\options.txt", "H:\Minecraft\.minecraft\options.txt"
    

    Include the filename in the folder that you copy to.

    0 讨论(0)
  • 2020-11-30 11:29

    Another thing to check is if any applications still have a hold on the file.

    Had some issues with MoveFile. Part of my permissions problem was that my script opens the file (in this case in Excel), makes a modification, closes it, then moves it to a "processed" folder.

    In debugging a couple things, the script crashed a few times. Digging into the permission denied error I found that I had 4 instances of Excel running in the background because the script was never able to properly terminate the application due to said crashes. Apparently one of them still had a hold on the file and, thusly, "permission denied."

    0 讨论(0)
  • 2020-11-30 11:34

    for me adding / worked at the end of location of folder. Hence, if you are copying into folder, don't forget to put /

    0 讨论(0)
  • 2020-11-30 11:35

    Based upon your source variable (sourcePath = "C:\Minecraft\bin\") I suspect your hard code is pointing at the wrong place

    fso.CopyFile "C:\Minecraft\options.txt", destinationPath, false
    

    should be

    fso.CopyFile "C:\Minecraft\bin\options.txt", destinationPath
    

    or

    fso.CopyFile sourcePath & "options.txt", destinationPath
    
    0 讨论(0)
  • 2020-11-30 11:36

    I have read your problem, And i had the same problem. But af ter i changed some, my problem "Permission Denied" is solved.

    Private Sub Addi_Click()
    'On Error Resume Next
    'call ds
    browsers ("false")
    Call makeAdir
    ffgg = "C:\Users\Backups\user\" & User & "1\data\"
    Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.Getfolder("c:\users\Backups\user\" & User & "1\data")
        f.Attributes = 0
    Set fso = VBA.CreateObject("Scripting.FileSystemObject")
    Call fso.Copyfile(filetarget, ffgg, True)
    

    Look at ffgg = "C:\Users\Backups\user\" & User & "1\data\", Before I changed it was ffgg = "C:\Users\Backups\user\" & User & "1\data" When i add backslash after "\data\", my problem is solved. Try to add back slash. Maybe solved your problem. Good luck.

    0 讨论(0)
  • 2020-11-30 11:38

    It's worth checking task manager for any stray wscript.exe tasks that are stuck. It could be one of those that's blocking access to the file.

    0 讨论(0)
提交回复
热议问题