One of our largest customers is upgrading to Windows7 and has reported that they now get a System.UnauthorizedAccessException when our application first loads. (No problem on WinXP)
The problem occurs at the following line: Infragistics.Win.AppStyling.StyleManager.Load(fs)(where 'fs' is a FileStream)
The file exists under the 'Program Files' branch, so it will be ReadOnly for a standard user.
Does the Load() function attempt to open this file for Write?If so, how do I tell it NOT to do that.If not, what else might cause an UnauthorizedAccess exception?
Hello ,
UnauthorizedAccessException is thrown when the operating system denies access because of an I/O error or a specific type of security error. So if you use Load method with string fileName parameter then StyleManager will execute the following code:
Stream stream = (Stream) File.OpenRead(fileName))
If you pass a stream as a parameter of the Load method then StyleManager will use the stream directly to read the isl file. So I do not think that StyleManager could cause this issue. However you could try to create an embedded Application Manifest with Your Application, this will allow non-manifested or unsigned code to run with a full administrative access token. How to do this you could find at the following link:
http://msdn.microsoft.com/en-us/library/bb756929.aspx
Other approach which you could try is to move your isl file to be stored in one of the following folder:
· CSIDL_PROFILE
· CSIDL_COMMON_APPDATA
When running under a managed desktop, an application only has write permission to the following folders and their children. For more information please review the following link:
http://msdn.microsoft.com/en-us/library/bb756940.aspx
Please let me know if you have any further questions.
Thanks for the very complete response.
I didn't think you would be opening it for Read/Write but I just wanted to be sure.
We have many other customers who are using the product without problems so it looks like they may have set up some unusual security rules and simply dont know (or are not admitting it to us)
I wanted to keep the isl files in the same directory as the executable in order to ensure that [standard]users dont start playing around with the files and then reporting problems when they mess them up.
Thanks.Mike
UAC is supposed to prevent changes to the system.In addition to the isl files we also have a dozen or so 'language' files in the program directory and we dont see any problems reading those.
I think the problem is specific to this customer so it must be some unusual security settings they have applied. When your customers are Fortune 100 companies you dont get to tell them how to set UAC settings - or anything else - I'm afraid.
Wherever possible I like to keep all 'data' files separate from the application. This allows us to quickly fix many problems by simply sending the customer a new file rather than having to build a whole new package. (This applies to isl, language, and vendor specific SQL files, amoung others.) We provide them with 9 isl files that they can easily switch between.
Anyway, thanks for the input. I think I have my questions answered.
I think this might be normal security for Windows 7 when UAC is turned on. I'm pretty sure that applications aren't supposed to access files in the Program Files folder.
You might want to ask your users to turn off UAC, just to see if that's the issue. But either way, I would recommend using a different folder and avoiding accessing files in the system folders.
If you don't need write access to the file, anyway, then you might also want to consider embedding the isl file in your exe instead of distributing it as a separate file.