windows 環境變量 %SystemDrive% 和 %SystemRoot%


%SYSTEMROOT% == c:\windows (or the root windows directory)

%SYSTEMDRIVE% == the drive windows is installed to (eg, C:\)

 

 

 

How can I get the system drive letter?

There's an environment variable called SystemDrive which is set to the system drive (surprisingly enough). The getenv() call is how you can get to it.

char *sysDrive = getenv ("SystemDrive"); if (sysDrive == NULL) { // vote me down. } else { // vote me up and use it. }



if(DWORD len = ::ExpandEnvironmentStrings(input, 0, 0)) {
if(len > 0) {
TCHAR *cp = new TCHAR[len];

 
        

if(cp) {
if(::ExpandEnvironmentStrings(input, cp, len) != 0) {

 
        

result = string(encodings::utf8, cp);
}
delete[] cp;
}
}
}




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM