Mega Code Archive

 
Categories / Delphi / System
 

How to determine the System Root

Title: How to determine the System Root Question: Many programs write "%SystemRoot%" in a registry value to give the location where Windows is installed. This article gives a function that can be used to determine the expanded path for SystemRoot. Answer: // Modified from bbwininf.zip at the Delphi Super Page. // The original function source code only checked the "Windows" key but not // the "Windows NT" key. // I have not tested this on Windows XP. function GetSystemRoot: string; begin with TRegistry.Create do try RootKey := HKEY_LOCAL_MACHINE; OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion', False); result := ReadString('SystemRoot'); if result = '' then begin CloseKey; OpenKey('SOFTWARE\Microsoft\Windows NT\CurrentVersion', False); result := ReadString('SystemRoot'); end; finally Free end end;