none
Permission Denied 800A0046 when writing to created text file. RRS feed

  • Question

  • All,

    I am processing a text file that contains a header that will be used to generate an email.  The remainder of the file will become the body of the email.  The file has an extension of .mail.  I am creating the output file to store the body with the text.  This works.  However, the very next line sets up the file for writing.  It fails with the error in the subject.  The file exists with zero bytes.  I have tried by moving the process to my laptop and providing full control to users on my laptop to no avail.  Any suggestions are welcome.  This has me stumped.

    Regards,

    David

    Code-----------------------------

    Const ForReading = 1
    Const ForWriting = 2

    MFolder = "D:\vmail\remit\"
    AFolder = "D:\vmail\remit\archive\"
    Set oFSOInput = CreateObject("Scripting.FileSystemObject")

    For Each oInputFile In oFSOInput.GetFolder(MFolder).Files
        oFileParts = split(oInputFile.Name,".") 
        oInputFileExt = oFileParts(1)
        oInputFileName = oFileParts(0)
        If LCase(oInputFileExt) = "mail" Then
            oOutputFileName = MFolder & oInputFileName & ".txt"
    Set oFSOOutput = CreateObject("Scripting.FileSystemObject")
    Set oOutputFile = oFSOOutput.CreateTextFile(oOutputFileName,True)
        Set oOutputFile = oFSOOutput.OpenTextFile(oOutputFileName,  ForWriting)
            ProcessFiles oFSOInput, oInputFile, oOutputFile
      End if
    Next

    Set oFSOInput = Nothing

    Sub ProcessFiles(FSOInput, InputFile, OutputFile)
        Set oInputFile2 = FSOInput.OpenTextFile(InputFile.path, ForReading)
        Do Until oInputFile2.AtEndOfStream
            strLine = oInputFile2.ReadLine
            strLineNo = strLineNo + 1
            If strLineNo <= 4 then
                If Left(strLine, 5) = "FROM:" then
                    mailfrom = Mid(strLine,6,52)
                End If
                If Left(strLine, 3) = "CC:" then
                    mailcc = Mid(strLine,4,52)
                End If
                If Left(strLine, 3) = "TO:" then
                    mailto = Mid(strLine,4,52)
                End If
                If Left(strLine, 8) = "SUBJECT:" then
                    mailsubj = Mid(strLine,9,80)
                End If
            Else
        objFile.Write strLine
                objFile.Close
            End If
        Loop
         oInputFile2.close
         set oInputFile2 = Nothing     
    end sub

    Tuesday, December 22, 2015 8:34 PM

Answers

  • You are trying to open an already opened file:

    Set oOutputFile = oFSOOutput.CreateTextFile(oOutputFileName,True)
    Set oOutputFile = oFSOOutput.OpenTextFile(oOutputFileName,  ForWriting)

    Do this:

    Set oOutputFile = oFSOOutput.OpenTextFile(oOutputFileName,  ForWriting, $true)


    \_(ツ)_/

    • Marked as answer by SquirrelMan Monday, January 4, 2016 2:15 PM
    Wednesday, December 23, 2015 8:22 PM

All replies

  • You cannot read and write a file at the same time


    \_(ツ)_/

    Tuesday, December 22, 2015 8:37 PM
  • There is no way to know what to do withut the complete and exact error message.


    \_(ツ)_/

    Tuesday, December 22, 2015 8:38 PM
  • ---------------------------
    Windows Script Host
    ---------------------------
    Script:    D:\Applications\v-email\email-proc.vbs
    Line:    16
    Char:    6
    Error:    Permission denied
    Code:    800A0046
    Source:     Microsoft VBScript runtime error

    ---------------------------
    OK   
    ---------------------------
    Wednesday, December 23, 2015 7:54 PM
  • You are trying to open an already opened file:

    Set oOutputFile = oFSOOutput.CreateTextFile(oOutputFileName,True)
    Set oOutputFile = oFSOOutput.OpenTextFile(oOutputFileName,  ForWriting)

    Do this:

    Set oOutputFile = oFSOOutput.OpenTextFile(oOutputFileName,  ForWriting, $true)


    \_(ツ)_/

    • Marked as answer by SquirrelMan Monday, January 4, 2016 2:15 PM
    Wednesday, December 23, 2015 8:22 PM
  • Thanks! That did the trick.
    Monday, January 4, 2016 2:15 PM