Windows system issue - LocalSystem account cannot read file

I created a Windows service to open an IIS log, read the content, and then send that content to consultants who "Human" doesn't want any access to those servers. Everything works fine on my local machine and the file generated by parsing the IIS log for the day is emailed to recipients.

I do not have access to install my service to the development system. I had the service administrator installed. The service has LocalSystem permissions. When the service starts, I get this message in the application log:

LogExtractor function: GetIISLog - C: \ WINDOWS \ system32 \ LogFiles \ W3SVC1 \ ex090918.log does not exist.

The administrator confirmed the path is correct and the file exists. (My user account does not have access to the W3SVC1 directory.) From what I understand, the system account is an uber account and can pretty much do what it wants, so I don’t understand why it cannot read the file. I am guessing this is a permissions issue as the files exist.

Here is the relevant code. I trimmed the logic involved in the section on reading a file. The code works because it runs successfully on one system but not the other, so I know the path is generated correctly. Any ideas?

Private Sub GetIISLog(ByVal LastRetrievedDate As DateTime)

    'Build the file path to store the IIS event log before sending it off (previous code snipped)
    Dim FileDate As String = "ex" & Date.Now.Year.ToString.Substring(2, 2) & Month & Day & ".log"
    Dim FileName As String = "C:\WINDOWS\system32\LogFiles\W3SVC1\" & FileDate

    'If the file doesn't exist, exit
    If Not File.Exists(FileName) Then
        LogIssues("LogExtractor: GetIISLog function - " & FileName & " does not exist.", EventLogEntryType.Error)
        Exit Sub
    End If

    Dim s As Stream = Nothing

    Try
        s = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
        Dim strResult As String = String.Empty

        Using sr As New StreamReader(s)
            Using sw As New StreamWriter(IISLogFile, False)

                strResult = sr.ReadLine

                While Not strResult Is Nothing

                    sw.WriteLine(strResult)

                    'Write the results
                    strResult = sr.ReadLine

                End While
            End Using

            sr.Close()
        End Using

        s.Close()
    Catch ex As Exception
        LogIssues("LogExtractor: Error writing IIS file - " & ex.Message, EventLogEntryType.Error)
    Finally
        s.Close()
    End Try

    s = Nothing

End Sub

      

+2


source to share


2 answers


I figured out the question. IIS was configured to log into the database, so the files I was looking for did not exist. Unfortunately, I don't have access to either the W3SVC1 folder or IIS, so I never knew that. I suppose when I asked the administrator the question "Is ex090920.log the correct format?" I should have asked if the file even exists.

Well, at least he decided, with (hopefully) no permanent damage from all the head bumps.



Thanks for your suggestions Stephen and he.

0


source


If the server is running a 64-bit OS, the most likely reason for this is that your two processes, IIS and the log processing service, are running at different bit rates.



In a 64-bit file system transfer of a machine, 32-bit processes access system32 to actually access SysWOW64. Therefore, if one of your processes is running as a 64-bit process and the other as a 32-bit process, they will actually access two different locations when they read or write to system32.

+1


source







All Articles