PC Review


Reply
Thread Tools Rate Thread

Can not create a new file with File.Create -- throws exception:Access Denied

 
 
thephatp
Guest
Posts: n/a
 
      28th Mar 2008
I'm trying to do something extremely basic, and I don't remember
having these problems in XP.

I'm running a service, logged in as an administrator. I created a
directory in windows explorer (as administrator), and set all
permissions/security for all users (including the Everyone group) to
full control.

The following code still does not work:

FileStream fs;
try
{

System.Windows.Forms.MessageBox.Show( this.sFileStoreLocation + "\\" +
sFilename + ".txt" );
fs = File.Create( this.sFileStoreLocation + "\\" +
sFilename + ".txt" );
}
catch( Exception e )
{
System.Windows.Forms.MessageBox.Show( e.ToString() );
fs = null;
}


Any ideas? Is this a Vista thing? I don't understand why it is so
difficult to do this right now (and I'm really suspecting Vista).

The scenario I need to work is this:

Any user logs in. My app starts running. The user does something and
my app will need to produce some logging. I check to see a directory
exists in my apps "Program Files" location. If not, the user needs to
be able to create it. All users will need to be able to write to this
directory. (I can't get directory creation to work either, but one
thing at a time--and I assume the solution will fix both problems.)
It will be a general logging location. The creation of the directory
is still important, because if it happends to get deleted, I want to
try to recreate it, not just be sunk for logging. And since I
wouldn't doubt one my clients could accidentally delete this folder, I
have to make it work in code.

Thanks,

Chad
 
Reply With Quote
 
 
 
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      28th Mar 2008
On Mar 27, 11:17*pm, thephatp <chad.a.mor...@gmail.com> wrote:
> I'm trying to do something extremely basic, and I don't remember
> having these problems in XP.
>
> I'm running a service, logged in as an administrator. *I created a
> directory in windows explorer (as administrator), and set all
> permissions/security for all users (including the Everyone group) to
> full control.
>
> The following code still does not work:
>
> * * * * * * FileStream fs;
> * * * * * * try
> * * * * * * {
>
> System.Windows.Forms.MessageBox.Show( this.sFileStoreLocation + "\\" +
> sFilename + ".txt" );
> * * * * * * * * fs = File.Create( this.sFileStoreLocation + "\\" +
> sFilename + ".txt" );
> * * * * * * }
> * * * * * * catch( Exception e )
> * * * * * * {
> * * * * * * * * System.Windows.Forms.MessageBox.Show( e.ToString() );
> * * * * * * * * fs = null;
> * * * * * * }
>
> Any ideas? *Is this a Vista thing? *I don't understand why it is so
> difficult to do this right now (and I'm really suspecting Vista).
>
> The scenario I need to work is this:
>
> Any user logs in. *My app starts running. *The user does something and
> my app will need to produce some logging. *I check to see a directory
> exists in my apps "Program Files" location. *If not, the user needs to
> be able to create it. *All users will need to be able to write to this
> directory. *(I can't get directory creation to work either, but one
> thing at a time--and I assume the solution will fix both problems.)
> It will be a general logging location. *The creation of the directory
> is still important, because if it happends to get deleted, I want to
> try to recreate it, not just be sunk for logging. *And since I
> wouldn't doubt one my clients could accidentally delete this folder, I
> have to make it work in code.
>
> Thanks,
>
> Chad


Hi

where this.sFileStoreLocation is pointing to?

And yes, it's possible it's a Vista "feature"
 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      28th Mar 2008
"thephatp" <(E-Mail Removed)> wrote in message
news:41888129-57dc-476e-a64a-(E-Mail Removed)...
> I'm trying to do something extremely basic, and I don't remember
> having these problems in XP.
>
> I'm running a service, logged in as an administrator. I created a
> directory in windows explorer (as administrator), and set all
> permissions/security for all users (including the Everyone group) to
> full control.
>
> The following code still does not work:
>
> FileStream fs;
> try
> {
>
> System.Windows.Forms.MessageBox.Show( this.sFileStoreLocation + "\\" +
> sFilename + ".txt" );
> fs = File.Create( this.sFileStoreLocation + "\\" +
> sFilename + ".txt" );
> }
> catch( Exception e )
> {
> System.Windows.Forms.MessageBox.Show( e.ToString() );
> fs = null;
> }
>
>
> Any ideas? Is this a Vista thing? I don't understand why it is so
> difficult to do this right now (and I'm really suspecting Vista).
>
> The scenario I need to work is this:
>
> Any user logs in. My app starts running. The user does something and
> my app will need to produce some logging. I check to see a directory
> exists in my apps "Program Files" location. If not, the user needs to
> be able to create it. All users will need to be able to write to this
> directory. (I can't get directory creation to work either, but one
> thing at a time--and I assume the solution will fix both problems.)
> It will be a general logging location. The creation of the directory
> is still important, because if it happends to get deleted, I want to
> try to recreate it, not just be sunk for logging. And since I
> wouldn't doubt one my clients could accidentally delete this folder, I
> have to make it work in code.
>
> Thanks,
>
> Chad



What's the sFileStoreLocation value?
Keep in mind that "administrator" (like all administrators account!) is just
a regular user account , unless you run elevated (which is not the case
here).

Also, using MessageBox.Show (or whatever System;Windows.Forms class method)
is a big NO NO in Vista, if you really need to display a (simple) message
box, you will have to PInvoke the WTSSendMessage API.

Willy.




 
Reply With Quote
 
thephatp
Guest
Posts: n/a
 
      30th Mar 2008
On Mar 28, 3:56*pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.be> wrote:
> "thephatp" <chad.a.mor...@gmail.com> wrote in message
>
> news:41888129-57dc-476e-a64a-(E-Mail Removed)...
>
>
>
>
>
> > I'm trying to do something extremely basic, and I don't remember
> > having these problems in XP.

>
> > I'm running a service, logged in as an administrator. *I created a
> > directory in windows explorer (as administrator), and set all
> > permissions/security for all users (including the Everyone group) to
> > full control.

>
> > The following code still does not work:

>
> > * * * * * *FileStream fs;
> > * * * * * *try
> > * * * * * *{

>
> > System.Windows.Forms.MessageBox.Show( this.sFileStoreLocation + "\\" +
> > sFilename + ".txt" );
> > * * * * * * * *fs = File.Create( this.sFileStoreLocation + "\\" +
> > sFilename + ".txt" );
> > * * * * * *}
> > * * * * * *catch( Exception e )
> > * * * * * *{
> > * * * * * * * *System.Windows.Forms.MessageBox.Show( e.ToString() );
> > * * * * * * * *fs = null;
> > * * * * * *}

>
> > Any ideas? *Is this a Vista thing? *I don't understand why it is so
> > difficult to do this right now (and I'm really suspecting Vista).

>
> > The scenario I need to work is this:

>
> > Any user logs in. *My app starts running. *The user does something and
> > my app will need to produce some logging. *I check to see a directory
> > exists in my apps "Program Files" location. *If not, the user needs to
> > be able to create it. *All users will need to be able to write to this
> > directory. *(I can't get directory creation to work either, but one
> > thing at a time--and I assume the solution will fix both problems.)
> > It will be a general logging location. *The creation of the directory
> > is still important, because if it happends to get deleted, I want to
> > try to recreate it, not just be sunk for logging. *And since I
> > wouldn't doubt one my clients could accidentally delete this folder, I
> > have to make it work in code.

>
> > Thanks,

>
> > Chad

>
> What's the sFileStoreLocation value?
> Keep in mind that "administrator" (like all administrators account!) is just
> a regular user account , unless you run elevated (which is not the case
> here).
>
> Also, using MessageBox.Show (or whatever System;Windows.Forms class method)
> is a big NO NO in Vista, if you really need to display a (simple) message
> box, you will have to PInvoke the WTSSendMessage API.
>
> Willy.- Hide quoted text -
>
> - Show quoted text -


The sFileStoreLocation is pointing to a new folder that I created,
like "C:\Temp_NEW\MyFolder\". I've given all groups full permissions
on this folder, and yet I still get an error. I could check each
user's temp directory, but I have two issues with that. In Vista, I'm
getting that the path is:

"C:\Users\MyUser\AppData\Local\Microsoft\Windows\Temporary Internet
Files\Virtualized\C\Users\MyUser\AppData\Local\Temp\Low\"


I'm not familiar with virtualized folders, but I went to Temporary
Internet Files and got what I expected (no `Virtualized` folder ,
but I also went to `C\Users\MyUser\AppData\Local\Temp\Low\`, but I
didn't see anything there either. So, knowing nothing about this is
my first problem. My second problem is that this would mean that I
have to check all user locations for files stored here. Oh, and I'll
want to create my own folder under this, like `MyAppLogs` so that I
can check them on the fly (in service). That's a real pain to have to
do that for each user. I'd like to be able to create a place where
all users can write to, and if the directory happens to get deleted,
that any user can recreate. However, if necessary, I could have the
background service do so (which would be running as system).

Any help? FYI, I'm using the System.IO.Path.GetTempPath() method.

Thanks again.
 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      30th Mar 2008
"thephatp" <(E-Mail Removed)> wrote in message
news:4ba1a95c-8e6f-41ec-a463-(E-Mail Removed)...
On Mar 28, 3:56 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.be> wrote:
> "thephatp" <chad.a.mor...@gmail.com> wrote in message
>
> news:41888129-57dc-476e-a64a-(E-Mail Removed)...
>
>
>
>
>
> > I'm trying to do something extremely basic, and I don't remember
> > having these problems in XP.

>
> > I'm running a service, logged in as an administrator. I created a
> > directory in windows explorer (as administrator), and set all
> > permissions/security for all users (including the Everyone group) to
> > full control.

>
> > The following code still does not work:

>
> > FileStream fs;
> > try
> > {

>
> > System.Windows.Forms.MessageBox.Show( this.sFileStoreLocation + "\\" +
> > sFilename + ".txt" );
> > fs = File.Create( this.sFileStoreLocation + "\\" +
> > sFilename + ".txt" );
> > }
> > catch( Exception e )
> > {
> > System.Windows.Forms.MessageBox.Show( e.ToString() );
> > fs = null;
> > }

>
> > Any ideas? Is this a Vista thing? I don't understand why it is so
> > difficult to do this right now (and I'm really suspecting Vista).

>
> > The scenario I need to work is this:

>
> > Any user logs in. My app starts running. The user does something and
> > my app will need to produce some logging. I check to see a directory
> > exists in my apps "Program Files" location. If not, the user needs to
> > be able to create it. All users will need to be able to write to this
> > directory. (I can't get directory creation to work either, but one
> > thing at a time--and I assume the solution will fix both problems.)
> > It will be a general logging location. The creation of the directory
> > is still important, because if it happends to get deleted, I want to
> > try to recreate it, not just be sunk for logging. And since I
> > wouldn't doubt one my clients could accidentally delete this folder, I
> > have to make it work in code.

>
> > Thanks,

>
> > Chad

>
> What's the sFileStoreLocation value?
> Keep in mind that "administrator" (like all administrators account!) is
> just
> a regular user account , unless you run elevated (which is not the case
> here).
>
> Also, using MessageBox.Show (or whatever System;Windows.Forms class
> method)
> is a big NO NO in Vista, if you really need to display a (simple) message
> box, you will have to PInvoke the WTSSendMessage API.
>
> Willy.- Hide quoted text -
>
> - Show quoted text -


The sFileStoreLocation is pointing to a new folder that I created,
like "C:\Temp_NEW\MyFolder\". I've given all groups full permissions
on this folder, and yet I still get an error. I could check each
user's temp directory, but I have two issues with that. In Vista, I'm
getting that the path is:

"C:\Users\MyUser\AppData\Local\Microsoft\Windows\Temporary Internet
Files\Virtualized\C\Users\MyUser\AppData\Local\Temp\Low\"


I'm not familiar with virtualized folders, but I went to Temporary
Internet Files and got what I expected (no `Virtualized` folder ,
but I also went to `C\Users\MyUser\AppData\Local\Temp\Low\`, but I
didn't see anything there either. So, knowing nothing about this is
my first problem. My second problem is that this would mean that I
have to check all user locations for files stored here. Oh, and I'll
want to create my own folder under this, like `MyAppLogs` so that I
can check them on the fly (in service). That's a real pain to have to
do that for each user. I'd like to be able to create a place where
all users can write to, and if the directory happens to get deleted,
that any user can recreate. However, if necessary, I could have the
background service do so (which would be running as system).

Any help? FYI, I'm using the System.IO.Path.GetTempPath() method.

Thanks again.


Normally all "users" should be able to create folders/files under the root,
which begs the question - are you *sure* you are getting an "Access Denied"
exception when trying to create a folder/file under the root ("C:\"), what
makes you so sure about it?
Don't run a Service as "Administrator", set your service to run in the
"Local Service" account, try to create a folder and a file, this should
work. If it doesn't check the security settings on the root.

Willy.





Willy.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getdrivelayout: create file fail! Access Denied (ERROR) Please he =?Utf-8?B?QnJlbnQgSi4=?= Windows Vista General Discussion 2 4th Apr 2007 06:04 AM
Cannot create file...access is denied Troy Windows Vista Performance 1 28th Feb 2007 05:51 AM
GetProcessByName throws InvalidOperation Exception : Access denied =?Utf-8?B?U2lsdmVyIE9haw==?= Microsoft Dot NET Framework 2 11th Feb 2006 09:24 PM
Access to create file on remote server denied =?Utf-8?B?VmljdG9y?= Microsoft ASP .NET 1 16th Aug 2005 10:22 AM
vcdeploy : error VCD0035: Failed to create the file system directory for the virtual directory. Access is denied. Dominic Microsoft VC .NET 0 17th Jun 2004 01:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:47 PM.