Skip to content

Application crashes silently at startup due to a not catched UnauthorizedAccessException #415

@vbaderks

Description

@vbaderks

I am running rapr.exe running under my normal user account, which has no admin rights.
This worked fine for years: Windows would ask the password of my local admin account and start running rapr.exe

It seems that a recent change in Windows has made security more strict. I am now getting a crash at startup due to an unhandled exception:

System.UnauthorizedAccessException
HResult=0x80070005
Message=Access to the path 'C:\Users\Victor\repos\DriverStoreExplorer\Rapr\bin\Debug\Rapr.log' is denied.
Source=mscorlib
StackTrace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at System.IO.File.Open(String path, FileMode mode, FileAccess access, FileShare share)
at Rapr.TextFileTraceListener.CreateLogFileStream() in C:\Users\Victor\repos\DriverStoreExplorer\Rapr\TextFileTraceListener.cs:line 45
at Rapr.TextFileTraceListener.CreateLogStreamWithCleanup() in C:\Users\Victor\repos\DriverStoreExplorer\Rapr\TextFileTraceListener.cs:line 30
at Rapr.TextFileTraceListener..ctor() in C:\Users\Victor\repos\DriverStoreExplorer\Rapr\TextFileTraceListener.cs:line 18
at Rapr.Program.Main() in C:\Users\Victor\repos\DriverStoreExplorer\Rapr\Program.cs:line 88

It seems rapr.exe tries to open a log file in the directory where rapr.exe is located. The admin account has read rights to that directory but no write rights...

The method CreateLogStreamWithCleanup() in TextFileTraceListener.cs only catches IOException exceptions and File.Open can throw also UnauthorizedAccessException.

Note: It may be more suitable to use Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) for the location for the log file, as the admin account should have always rights to write to its own localapplicationdata folder. Disabling logging if an exception occured would also be a n alternative (instead of crashing...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions