Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Wednesday, May 19, 2010 5:39 PM
Hi,
I'm trying to run a simple console app on Win7 VS2010.
Here's the code:
using (FileStream stw = new FileStream(@"c:\OrdersToday.pdf", FileMode.Create))
{
stw.Write(rptBytes,0,rptBytes.Length);
}
using (FileStream stw = new FileStream(@"c:\MyFile.pdf", FileMode.Create))
{
stw.Write(myBytes,0,rptBytes.Length);
}
I get an UnauthorizedAccessException stating that I don't have rights to my own C drive (which I do).
This never happened in XP /VS2008.
Thanks,
John
All replies (10)
Monday, May 24, 2010 12:40 PM ✅Answered
Web application does not run under user credentials. It is running as a network service account for security reasons and hence it has very limited privileges. Also, server process does not require any user to be logged on and it can be replicated to different servers without having user account replicated.
You can use ASP.NET impersonation and change account under which your process runs or change permissions for the network service account. However, please be careful - running network service open to external requests as elevated account may lead to big security issues.
Monday, May 24, 2010 12:41 PM ✅Answered
In console apps you still cannot write to C since elevation is required even for admin account.
Wednesday, May 19, 2010 5:45 PM
Try setting the access permissions to "Full control" to user
Edit:
I assumed it's an Asp.Net app. So fixed the post.
Wednesday, May 19, 2010 5:50 PM
can you make a new folder on c: "by hand" with Windows Explorer ?
if not, please see
http://www.addictivetips.com/windows-tips/windows-7-access-denied-permission-ownership/
LaterEdit : @budugu :console application is not asp.net ...
Wednesday, May 19, 2010 7:14 PM
By default in Win7, users don't have write permissions for the system drive, Windows, and Program Files directories. You need to run you program as an administrator to be able to modify the file contents. For development, you should be able to run VS as an administrator, and then your app will inherit those permissions as well when you debug.
Thursday, May 20, 2010 7:52 AM
I'm logged in as an administrator, and have full control rights to the C Drive. Maybe "Full Control" means something different now.
Thursday, May 20, 2010 11:46 AM
As of Vista, if you're logged in as a member of the Administrators group you will actually use a non-admin security token by default. You need to explicitly elevate the process (i.e. "Run as adminstrator") when you launch it to use a full Administrator security token; some processes will prompt you if elevation is required (this is the UAC prompt). Any processes running with the admin token will launch child processes with the admin token as well, which is why you can run VS elevated and your app will run elevated as well on F5.
Thursday, May 20, 2010 3:09 PM
Running as administrator makes that annoying UAC box come up. Is there any way to remove that silly lock on the C drive?
Thursday, May 20, 2010 4:56 PM
I don't know of a way to do it other than disabling UAC. You could create a folder, e.g. C:\foo, and drop the file in there...
Sunday, June 19, 2011 3:02 PM
Elevation for "Admin" account? But why?? Don't you guys anything useful to do instead of devising these humuliating ways to annoy and offend and insult public?
Who asked you to introduce this feature? Was it a request of an idea of few of you brialliant geniuses?
If elevation is required, why can't yu tell how to DO THAT?????