Question Reading a Windows file

Alan048

New member
Joined
Jan 12, 2011
Messages
2
Programming Experience
5-10
I am trying to open for reading a Windows file (used in XP through 7) for reading. However, even though I provide a complete location ("C:\Windows\system32\config\default"), I get a file not found exception.

The file's only unusual attribute is "A" (archive?). My code, shown below, gets the exception at this line, when I try to open it:

logFileStream = New FileStream("C:\Windows\system32\config\default", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)

Can anyone tell me how to access this file?

Thanks, Alan

Dim logFileStream As System.IO.FileStream, logFileReader As System.IO.StreamReader, line As String
logFileStream = New FileStream("C:\Windows\system32\config\default", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
logFileReader = New StreamReader(logFileStream)

While (Not logFileReader.EndOfStream)
line = logFileReader.ReadLine()
Debug.Print(line)
TextBox1.Text = TextBox1.Text & line & vbCrLf
End While

logFileReader.Close()
logFileStream.Close()
 
IOException: The process cannot access the file 'c:\windows\system32\config\default' because it is being used by another process.
According to Process Explorer the file is locked by Windows system.
 
JohnH:

Is there any way I could just read it? I don`t want to write to it.

Also, why do I get a FileNotFoundException? It doesn`t even find the file, so this does not sound like an access problem.

Thanks, Alan
 
Is there any way I could just read it
No, not to my knowledge there isn't.
Also, why do I get a FileNotFoundException?
Perhaps your current user has limited access to system folders.
 
Back
Top