开发者

Is there a way to tell if a directory specified by the user is a protected directory in Windows 7/Vista with UAC enabled (and not running as admin)

开发者 https://www.devze.com 2023-04-08 12:32 出处:网络
There are several points where the user can specify a what directory that data is to be saved to, I would like to be able to notify the user if they have chosen a directory that is being protected by

There are several points where the user can specify a what directory that data is to be saved to, I would like to be able to notify the user if they have chosen a directory that is being protected by Windows.开发者_开发问答 I can just write a file to see if the OS lets me because UAC will write the file to a different directory.


You can try to write a temporary file to the directory. If the directory is UAC protected and you're not running under admin privileges you will get a System.UnauthorizedAccessException error.

Edit: If @JoeWhite is correct and you are attempting to determine when your application is being affected by UAC Virtualization. I don't believe you can detect that in the application itself. The write calls will be adjusted by the OS automatically without any notice to your application.

You can read more on how UAC Virtualization works at via this article on the Windows Team Blog.

This only affects these specific cases though:

Your application writes to Program Files, Windows directories, or the system root (typically the C drive) folders

Your application writes to the Windows registry, specifically to HKLM/Software

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号