请参阅“程序文件”在 64 位机器上

发布于 2024-08-04 21:15:38 字数 79 浏览 1 评论 0原文

在 C# 中,如何引用以下位置而不是对其进行硬编码?

  • 程序文件 (x86)
  • 程序文件

In C#, how do I refer the following locations rather than hard-coding them?

  • Program Files (x86)
  • Program Files

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲影 2024-08-11 21:15:38

您可以使用:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles);

获取机器上的程序文件夹。这将返回正在运行的应用程序的正确内容。因此,对于 64 位计算机上的 32 位应用程序,它将在英文版 Windows 上返回“C:\Program Files (x86)”。

You can use:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles);

to get the program files folder on the machine. This will return whatever is correct for the application that is running. So for 32-bit applications on a 64-bit machine, it will return "C:\Program Files (x86)" on a English version of Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文