我知道以下应该有效:
Environment.GetEnvironmentVariable("windir", EnvironmentVariableTarget.Machine)
我对这个调用的问题是,如果出于某种原因有人决定删除“windir”Env Var,这将不起作用。
是否有更安全的方法来获取系统驱动器?
最佳答案
string windir = Environment.SystemDirectory; // C:\windows\system32
string windrive = Path.GetPathRoot(Environment.SystemDirectory); // C:\
注意:此属性在内部使用 GetSystemDirectory() Win32 API。它不依赖于环境变量。
关于c# - 检索系统驱动器的最安全方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/910004/