在任何版本的 Windows 下以任何语言写入文件的通用位置
必须在 Windows XP 下的多台计算机上部署 VBA 应用程序,我需要在通用位置自动创建一个特定的文件,独立于硬盘驱动器、目录结构,甚至操作系统语言:C 驱动器的根目录,即 C: \
这工作得很好......直到这些计算机开始迁移到 Vista 或 Windows 7,我发现它们不容易允许在 C 驱动器上写入。 可以在任何版本的 Windows 下、以任何语言、为所有用户工作的替代通用可写位置是什么?
Having to deploy a VBA application on several computers under Windows XP, I needed to automatically create a particular file in an universal place, independent of hard drives, directory structure, even the OS language: the root directory of the C drive, namely C:\
This worked fine ... until these computers started to migrate to Vista or Windows 7, which I discovered don't easily allow writing on the C drive.
What could be an alternate universal writable location that would work under any version of Windows, in any language, for all users?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用一个 Windows API,该 API 返回相应计算机上
SpecialFolder
的路径并使用它 - 例如CSIDL_COMMON_DOCUMENTS
(非用户特定)CSIDL_COMMON_APPDATA 非常适合
(非用户特定)CSIDL_APPDATA
(用户/应用特定)CSIDL_MY_DOCUMENTS
(用户特定)Windows API 负责处理您所描述的所有内容 - 上面的位置是可写的,适用于所有 Windows 版本,并且不依赖于语言。
有关 VBA 源代码和示例,请参阅 http://www.cpearson.com/excel/SpecialFolders.aspx
有关 MSDN 参考,请参阅:
Call a Windows API that returns the path to a
SpecialFolder
on the respective machine and use that - well suited are for exampleCSIDL_COMMON_DOCUMENTS
(non-user-specific)CSIDL_COMMON_APPDATA
(non-user-specific)CSIDL_APPDATA
(user-/app-specific)CSIDL_MY_DOCUMENTS
(user-specific)The Windows API takes care of all that you described - locations above are writeable, work for all Windows versions and not language-dependent.
For VBA source code and samples see http://www.cpearson.com/excel/SpecialFolders.aspx
For MSDN references see: