VBscript Permission Denied 800A0046 Solution

I was helping a friend write some VBscript the other day. I was trying to write a simple copy function and I kept getting permission denied. However I was logged in locally as the administrator so that could not be it.

My code looked something like:

Sub CopyFile(source, destination)
	set filesys=CreateObject("Scripting.FileSystemObject")
	If filesys.FileExists(source) Then
	   filesys.CopyFile source, destination
	End If

End Sub

The Solution is: add “\” add the end of any of your path names like
Dim destinationpath
destinationpath = “C:\” & myfolder & “\”

Hope this helps someone else.

29 comments

  1. Finally! I was editing a 200+ vbs login script and got stuck on this error. Everything seemed fine, but the “Permission denied”. Even checked the permissions on both the source and destination folders, no good.

    Then I found this post and VOILA!!! Everything is good again and I’m a happy camper!!

    THANK YOU SO MUCH!

  2. Hi, please help me as I am getting the same error message, the script9to get patch information on multiple servers) is as follows :

    Option Explicit

    Dim objFSO, objTextFile, RootDir, FileOutput, strComputer, objWMIService, Count

    Const ForReading = 1

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objTextFile = objFSO.OpenTextFile(“C:\scripts\input.txt”, ForReading)

    Dim strHotFix
    strHotFix = inputbox(“2667402”)

    set FileOutput = objFSO.CreateTextFile(“C:\scripts\Pat_Install_Status_KB.htm”,true,false)

    fileOutput.WriteLine(“Installed Patches Information”)
    fileOutput.WriteLine(“”)
    fileOutput.WriteLine(“”)
    fileOutput.WriteLine(“Computer NameDescriptionHotfix IDInstall StatusInstalled OnInstalled By”)

    Do Until objTextFile.AtEndOfStream
    strComputer = objTextFile.Readline
    Count = 0
    ‘Query command
    Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)

    Dim QFEs
    Set QFEs = objWMIService.ExecQuery (“Select * from win32_QuickFixEngineering”)

    Dim strOutput
    Dim QFE
    For Each QFE in QFEs
    if QFE.HotFixID = strHotFix then
    strOutput = “”
    strOutput = strOutput + “” & strComputer & “” &_
    “” & QFE.Description & “” &_
    “” & QFE.HotFixID & “” &_
    “” & “Installed” & “” &_
    “” & QFE.InstalledOn & “” &_
    “” & QFE.InstalledBy & “”
    Count= Count + 1
    fileOutput.WriteLine(strOutPut)
    fileOutput.WriteLine(“”)
    end if

    ‘ strOutPut=””
    Next
    if Count = 0 then
    strOutput = “”
    strOutput = strOutput + “” & strComputer & “” &_
    “” & “-” & “” &_
    “” & strHotfix & “” &_
    “” & “Not Installed” & “” &_
    “” & “-” & “” &_
    “” & “-” & “”
    fileOutput.WriteLine(strOutPut)
    fileOutput.WriteLine(“”)
    end if
    Loop

    fileOutput.WriteLine(“”)
    wscript.echo “Result saved in Pat_Install_Status_KB.html file at specified location in line no 15 of this script”
    WScript.Quit

  3. I’ve been searching different articles for hours. This is the only one I found with this solution and it worked like a charm! Thanks!

  4. Great post.

    For the ones of you who user server.mappath(“/folder/”)
    that WILL NOT work!

    you should use: server.mappath(“/folder”)&”/”
    since server.mappath will remove your last “/”

    Hope that helps 🙂

  5. I have a website which has links to .xml files.. i need to save the the files which came in today. is ther a way i can accomplish this using VB script?

  6. We are getting the same error. here is my line 19 that gets the error
    Set objlogfile = fso.OpenTextFile(fTMP & “\” & ScriptLogName, 2, True)

Leave a Reply