How do get the path of Program Files regardless of the architecture of the target machine

非 Y 不嫁゛ 提交于 2019-11-29 16:50:31

问题


I'm programming in C#/.NET. I want to be able to return the Program Files directory from the target machine no matter what the architecture of the target machine is. To clarify, I want it to return C (or whatever drive the OS is on):/Program Files no matter what bitness their version of Windows is.

I could just hardcode in the directory except if the user was running Windows that's not installed on the C: drive it wouldn't work.

I found

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

but I think it returns the Program Files (x86) folder on a 64 bit windows machine.


回答1:


System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) returns "c:\Program Files" on a 64-bit machine, unless the code is build to target x86, in which case it returns "C:\Program Files (x86)", so I guess that would work for you.



来源:https://stackoverflow.com/questions/2284725/how-do-get-the-path-of-program-files-regardless-of-the-architecture-of-the-targe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!