title: Windows service problem - LocalSystem account cannot read file
body: <p>I have created a Windows service to open the IIS log, read content, then e-mail this content to consultants that 'The Man' doesn't want to have any access to those servers. On my local machine, everything works great, and the file generated from parsing the IIS log for the day is e-mailed to the recipients.</p>
  
  <p>I do not have access to install my service on the development system. I had the administrator install the service. The service has LocalSystem permissions. When the service runs, I receive this message in the Application log:</p>
  
  <p>LogExtractor: GetIISLog function - C:\WINDOWS\system32\LogFiles\W3SVC1\ex090918.log does not exist.</p>
  
  <p>The administrator has confirmed that the path is correct, and the file does exist. (My user account does not have access to the W3SVC1 directory.) It was my understanding that the System account is the uber-account, and can do pretty much what it wants, so I'm at a loss as to why it cannot read the file. I'm assuming it's a permissions issue, since the files does exist.</p>
  
  <p>Here is the relevant code. I've snipped the logic involved in the section about reading the file. The code works, as it runs successfully on one system, but not another, so I know the path is being generated correctly. Any ideas?</p>
  
  <pre><code>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" &amp; Date.Now.Year.ToString.Substring(2, 2) &amp; Month &amp; Day &amp; ".log"
      Dim FileName As String = "C:\WINDOWS\system32\LogFiles\W3SVC1\" &amp; FileDate
  
      'If the file doesn't exist, exit
      If Not File.Exists(FileName) Then
          LogIssues("LogExtractor: GetIISLog function - " &amp; FileName &amp; " 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 - " &amp; ex.Message, EventLogEntryType.Error)
      Finally
          s.Close()
      End Try
  
      s = Nothing
  
  End Sub
  </code></pre>