AndyC said:

The obvious question would be "Why not just write the temp file to the temp directory in the first place?"

 

Putting that aside for a moment, the default ACLs on C:\ dont allow the creation of files, only folders. So if the file isn't pre-existing it's definitely going to fail without Administrator rights. Assuming you have pre-created the file, dumping the ACLs and posting them here in SDDL will probably mke it easier to figure out what's going on.

 

It might also depend on how you're manipulating the file, attempting to write to it by recreating it might fall foul of the parent folder's NTFS permissions (though NT does some funky stuff to try to prevent that).

Sorry I just realised my original post spoke about temp file (I named it blah.tmp originaly, better name is blah.cache) and I just edited out mentions of that.

 

The operations I need to perform:

 

Everytime, I'd like to do this without UAC popups to the file in the root:

 Stream stream = new FileStream(persistfile, FileMode.Open, FileAccess.Write, FileShare.None);

 

The following isn't really mandatory but having it hidden shouldn't impede from modifying it afaik.

 

 ///.... modify content and close

 

File.SetAttributes(persistfile, FileAttributes.Hidden | FileAttributes.NotContentIndexed);