VirtualStore 无法在 Vista x64 上运行
我有一个小托盘应用程序想要写入 Program Files 目录下自己的文件夹。 我知道这不是最终的设计,我会修复它,但首先我想了解它是如何工作的。
在 32 位 Vista 机器上运行它,它会将文件写入 VirtualStore,并且它会正常工作。
但是,当在 Vista 64 位计算机上安装此程序时,我立即遇到 UnauthorizedAccessException,因为我尝试写入 Program Files(和 Program Files (x86))中的目录。
VirtualStore 重定向似乎不适用于 Vista 64 位。 有任何想法吗?
它是一个用 Visual Studio 2008 编写的 C# 应用程序,我使用 FileStream 对象将流保存到磁盘。
I have a little tray application that wants to write to its own folder under the Program Files directory. I know this is not an ultimate design and I will fix it, but first I want to understand how this works.
Running this on a 32-bit Vista machine it writes the files to the VirtualStore and it works just like it should.
But when installing this on a Vista 64-bit machine I immediately get hit with an UnauthorizedAccessException for trying to write to the directory within Program Files (and Program Files (x86)).
The VirtualStore redirect does not seem to work on Vista 64-bit. Any ideas?
It's a C# app written in Visual Studio 2008 and I use a FileStream obj to persist the stream to disk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
了解有关错误的更多信息?
您是否使用 sysinternals 工具来监视执行/访问错误?
也看看事件查看器是否有错误。
Have more info about error ?
Do you use sysinternals tools for monitor execution/access errors ?
Take a look Event viewer for error too.
我现在就修好它。 无论如何,您都不应该将您的内容写入该目录,这违反了准则。 当有多个用户同时登录服务器时,即使是 VISTA 之前的版本,您的产品也将无法工作。
Vista 64 位将检测到您是 32 位应用程序,并会自动将您尝试将“Program Files”修改为“Program Files x86”的尝试重定向。 事实上,它完全让您相信您正在 32 位系统上运行(请参阅 此处)。
我怀疑这个模拟层有额外的保护,可以防止程序尝试更改程序文件下的内容。 或者也许 ACL 在 Vista 64 位下设置得更好(或者更有可能是模拟层)。
底线:不要做你正在做的事情,微软已经告诉我们不要这样做很长时间了。
I'd just fix it now. You should never have been writing your stuff to that directory anyway, it violates the guidelines. Your product won't work when there's multiple users logged on to the server at the same time, even pre-VISTA.
Vista 64-bit will detect that you're a 32-bit app and will automagically redirect your attempts at modifying "Program Files" to "Program Files x86". In fact, it totally makes you believe you're running on a 32-bit system (see here).
I suspect there's extra protection in this emulation layer from programs trying to change things under Program Files. Or maybe the ACLs are set better under Vista 64-bit (or the emulation layer which is more likely).
Bottom line: don't do what you're doing, Microsoft has been telling us not to do that for a long time now.
因此,我实际上是通过将所有项目编译到目标平台 x86 来实现此目的的。 因此 x64 不能与 Vista 64 上的 VirtualStore 一起使用,也不能编译到“任何 CPU”。 我必须为整个解决方案(在配置管理器中)设置它,仅仅为每个单独的项目设置它是行不通的。
是时候使用 AppData 文件夹或isolatedStorage 重写它了。 感谢您的帮助!
So I actually got this working by compiling all projects to target platform x86. So x64 does not work with VirtualStore on Vista 64 and neither does compiling to "Any CPU". And I had to set it for the entire solution (in the Configuration Manager), just setting it for each individual project didn't work.
Time to rewrite it using AppData folder or IsolatedStorage. Thanks for all the help!