.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Windows Vista - UnauthorizedAccessException.
 

Windows Vista - UnauthorizedAccessException.

Problem

FileStream stream = new FileStream(@"C:\File.file", FileMode.Create, FileAccess.ReadWrite);

History

This snippet of code, of course, works perfectly fine in Windows XP. In the move to Windows Vista securityexceptions are a problem now. Also, telling a client to "Run as administrator" is not an option. It should work off the bat.

Question

What do I need to add/do to my code to prevent security problems in Windows Vista applications?

Ðãvę Âņđęŕŝőŋ2

You are running into UAC issues for Vista. General information about this is available here:

http://technet.microsoft.com/en-us/windowsvista/aa906021.aspx

In short, you have 3 options here:

1. Don't try to access a protected area of the file system (instead go to c:\users\account\etc. and you should be fine)

2. Elevate. Meaning this application runs as administrator bypassing UAC (either once or always)

3. Have the application prompt the user when reaching this code. If you are interested in doing #3 - you might want to check Daniel Moth's blog for more information: http://www.danielmoth.com/Blog/2006/11/uac-get-your-links-here.html

Inbar Gazit

You are running into UAC issues for Vista. General information about this is available here:

http://technet.microsoft.com/en-us/windowsvista/aa906021.aspx

In short, you have 3 options here:

1. Don't try to access a protected area of the file system (instead go to c:\users\account\etc. and you should be fine)

2. Elevate. Meaning this application runs as administrator bypassing UAC (either once or always)

3. Have the application prompt the user when reaching this code. If you are interested in doing #3 - you might want to check Daniel Moth's blog for more information: http://www.danielmoth.com/Blog/2006/11/uac-get-your-links-here.html

Inbar Gazit
I'm trying to access the following path from a VS plugin and I'm seeing an UnauthroizedAccessException.

C:\Users\Chris\AppData\Roaming\Microsoft\VisualStudio\9.0\ProjectTemplatesCache\Visual Web Developer

I'm users\chris so I figure I should have access to all the sub-directories.

Any idea what i can do to diagnose this issue?

Thanks,
Chris
kingces95
This sounds like a different issue. The file is in use by some other application and therefore you can't access it. Which VS plugin is this?

Inbar Gazit

You can use google to search for other answers

Custom Search

More Threads

• Icon in a DLL
• CodeCompileUnit and referencing an in memory assembly
• Did asynchronous execution change in 2.0
• COM API for Generating MOF files from MIB files
• DomainManager works on VS shell work but not on cmd shell...?!
• Using WMI from C#
• remove line break from word doc using c#
• NullReferenceException when using MethodBody in reflection
• object reference
• querring data from tables in different connection