Home All Groups Group Topic Archive Search About

System.UnauthorizedAccessException - Using win forms application opening file - Urgent

Author
11 Sep 2006 11:53 AM
Matt Adamson
I have some very simple code

FileStream fileStream = new
FileStream(@"K:\Development\Projects\POReport.asp", FileMode.Open);



Which throws an exception

Unhandled Exception: System.UnauthorizedAccessException: Access to the path
"K:\Development\Projects\POReport.asp" is denied



I could understand if this was an ASP.NET issue however as it's run using
the interactive account it's very strange.

Any ideas on how I can progress this issue e.g. are there tools I can use to
determine why were getting access to denied.

Author
11 Sep 2006 11:08 AM
Dominick Baier
hi,

a) make sure you *really* have access to that file
b) have a look at FileMon from www.sysinternals.com

---
Dominick Baier, DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> I have some very simple code
>
> FileStream fileStream = new
> FileStream(@"K:\Development\Projects\POReport.asp", FileMode.Open);
>
> Which throws an exception
>
> Unhandled Exception: System.UnauthorizedAccessException: Access to the
> path "K:\Development\Projects\POReport.asp" is denied
>
> I could understand if this was an ASP.NET issue however as it's run
> using the interactive account it's very strange.
>
> Any ideas on how I can progress this issue e.g. are there tools I can
> use to determine why were getting access to denied.
>
Author
11 Sep 2006 3:12 PM
Matt Adamson
Thanks however

1) I've given Everyone access to the file and no one else has it open. I've
used file handle by sysinternals to verify this
2) The file mon output is shown below

16:10:04 EAASPParser.exe:4516 IRP_MJ_CREATE
K:\Development\Projects\EAASPParser\POReport.asp ACCESS DENIED Attributes: N
Options: Open

Is there anything else I can try?

Show quoteHide quote
"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in
message news:4580be63135558c8a3ba71d115a0@news.microsoft.com...
> hi,
> a) make sure you *really* have access to that file
> b) have a look at FileMon from www.sysinternals.com
>
> ---
> Dominick Baier, DevelopMentor
> http://www.leastprivilege.com
>
>> I have some very simple code
>>
>> FileStream fileStream = new
>> FileStream(@"K:\Development\Projects\POReport.asp", FileMode.Open);
>>
>> Which throws an exception
>>
>> Unhandled Exception: System.UnauthorizedAccessException: Access to the
>> path "K:\Development\Projects\POReport.asp" is denied
>>
>> I could understand if this was an ASP.NET issue however as it's run
>> using the interactive account it's very strange.
>>
>> Any ideas on how I can progress this issue e.g. are there tools I can
>> use to determine why were getting access to denied.
>>
>
>
Author
11 Sep 2006 5:20 PM
Joe Kaplan
Did it say what account was denied access when you tried to open it?  That
might help establish the problem.  For example, if the anonymous user was
used and anonymous user is not configured to be part of "everyone" in the
local security policy, then "everyone" would not be sufficient.  The proper
way to solve that problem would be to fix the authentication problem so that
you can authenticate remotely rather than giving the anonymous user access.

Joe K.

--
Joe Kaplan-MS MVP Directory Services Programming
Co-author of "The .NET Developer's Guide to Directory Services Programming"
http://www.directoryprogramming.net
--
Show quoteHide quote
"Matt Adamson" <Adamson_matt***@hotmail.com> wrote in message
news:uf1a5Sb1GHA.1252@TK2MSFTNGP04.phx.gbl...
> Thanks however
>
> 1) I've given Everyone access to the file and no one else has it open.
> I've used file handle by sysinternals to verify this
> 2) The file mon output is shown below
>
> 16:10:04 EAASPParser.exe:4516 IRP_MJ_CREATE
> K:\Development\Projects\EAASPParser\POReport.asp ACCESS DENIED Attributes:
> N Options: Open
>
> Is there anything else I can try?
>
> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in
> message news:4580be63135558c8a3ba71d115a0@news.microsoft.com...
>> hi,
>> a) make sure you *really* have access to that file
>> b) have a look at FileMon from www.sysinternals.com
>>
>> ---
>> Dominick Baier, DevelopMentor
>> http://www.leastprivilege.com
>>
>>> I have some very simple code
>>>
>>> FileStream fileStream = new
>>> FileStream(@"K:\Development\Projects\POReport.asp", FileMode.Open);
>>>
>>> Which throws an exception
>>>
>>> Unhandled Exception: System.UnauthorizedAccessException: Access to the
>>> path "K:\Development\Projects\POReport.asp" is denied
>>>
>>> I could understand if this was an ASP.NET issue however as it's run
>>> using the interactive account it's very strange.
>>>
>>> Any ideas on how I can progress this issue e.g. are there tools I can
>>> use to determine why were getting access to denied.
>>>
>>
>>
>
>
Author
11 Sep 2006 9:59 PM
Dominick Baier
access means read/write

you should explicitly specify which access you need in the FileStream ctor...

---
Dominick Baier, DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> Thanks however
>
> 1) I've given Everyone access to the file and no one else has it open.
> I've
> used file handle by sysinternals to verify this
> 2) The file mon output is shown below
> 16:10:04 EAASPParser.exe:4516 IRP_MJ_CREATE
> K:\Development\Projects\EAASPParser\POReport.asp ACCESS DENIED
> Attributes: N Options: Open
>
> Is there anything else I can try?
>
> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote
> in message news:4580be63135558c8a3ba71d115a0@news.microsoft.com...
>
>> hi,
>> a) make sure you *really* have access to that file
>> b) have a look at FileMon from www.sysinternals.com
>> ---
>> Dominick Baier, DevelopMentor
>> http://www.leastprivilege.com
>>> I have some very simple code
>>>
>>> FileStream fileStream = new
>>> FileStream(@"K:\Development\Projects\POReport.asp", FileMode.Open);
>>> Which throws an exception
>>>
>>> Unhandled Exception: System.UnauthorizedAccessException: Access to
>>> the path "K:\Development\Projects\POReport.asp" is denied
>>>
>>> I could understand if this was an ASP.NET issue however as it's run
>>> using the interactive account it's very strange.
>>>
>>> Any ideas on how I can progress this issue e.g. are there tools I
>>> can use to determine why were getting access to denied.
>>>
Author
12 Sep 2006 5:40 AM
Matt Adamson
Thanks I actually just tried this

   FileStream fileStream = new
FileStream((@"K:\Development\Projects\POReport.asp", FileMode.Open,
FileAccess.Read);

and it worked.

I still don't understand why omitting the third param FileMode.Open caused
this to fail. The MSDN documentation states it is given read / write access
to the file so should why should this be an issue?

Show quoteHide quote
"Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote in
message news:4580be63135918c8a4157a550b40@news.microsoft.com...
> access means read/write
>
> you should explicitly specify which access you need in the FileStream
> ctor...
>
> ---
> Dominick Baier, DevelopMentor
> http://www.leastprivilege.com
>
>> Thanks however
>>
>> 1) I've given Everyone access to the file and no one else has it open.
>> I've
>> used file handle by sysinternals to verify this
>> 2) The file mon output is shown below
>> 16:10:04 EAASPParser.exe:4516 IRP_MJ_CREATE
>> K:\Development\Projects\EAASPParser\POReport.asp ACCESS DENIED
>> Attributes: N Options: Open
>>
>> Is there anything else I can try?
>>
>> "Dominick Baier" <dbaier@pleasepleasenospam_leastprivilege.com> wrote
>> in message news:4580be63135558c8a3ba71d115a0@news.microsoft.com...
>>
>>> hi,
>>> a) make sure you *really* have access to that file
>>> b) have a look at FileMon from www.sysinternals.com
>>> ---
>>> Dominick Baier, DevelopMentor
>>> http://www.leastprivilege.com
>>>> I have some very simple code
>>>>
>>>> FileStream fileStream = new
>>>> FileStream(@"K:\Development\Projects\POReport.asp", FileMode.Open);
>>>> Which throws an exception
>>>>
>>>> Unhandled Exception: System.UnauthorizedAccessException: Access to
>>>> the path "K:\Development\Projects\POReport.asp" is denied
>>>>
>>>> I could understand if this was an ASP.NET issue however as it's run
>>>> using the interactive account it's very strange.
>>>>
>>>> Any ideas on how I can progress this issue e.g. are there tools I
>>>> can use to determine why were getting access to denied.
>>>>
>
>