Get Windows System32 folder? lazarus / 34-Windows ---------------------------------------------------------------------- MisterKode · 2014-05-04 11:02 Hi everyone Sorry if this might be covered way back - I tried to find but gave up I want to winexec the Windows Defrag and also Windows Disk Cleanup on a user's PC in the tool I'm writing - but can someone please tell me how to get the current folder of their Windows System folder? I've tried a couple of different ways but always came to an exception when trying to run them Thanks in anticipation! Carl ---------------------------------------------------------------------- Bart · 2014-05-04 11:31 Take a look at windirs unit. CSIDL_SYSTEM or CSIDL_SYSTEMX86 is the ID you are looking for. (see: http://msdn.microsoft.com/en- us/library/windows/desktop/bb762494%28v=vs.85%29.aspx Bart ---------------------------------------------------------------------- JanRoza · 2014-05-04 11:36 You might want to download the free CodeSnip database which is full of handy pieces of coding for all kind of purposes http://www.delphidabbler.com/software/codesnip/download Function below comes from this database and is what you want I think: Code: [Select]function SystemFolder: string; begin   SetLength(Result, Windows.MAX_PATH);   SetLength(     Result, Windows.GetSystemDirectory(PChar(Result), Windows.MAX_PATH)   ); end; Just add the Windows unit in your uses clause and you're up and running with this function. ---------------------------------------------------------------------- MisterKode · 2014-05-04 11:39 Thanks heaps - will try these out tomorrow! ---------------------------------------------------------------------- engkin · 2014-05-04 14:38 You can also use environment variable %windir% or %systemroot%. By the way, if the point is to "winexec the Windows Defrag and also Windows Disk Cleanup" you do not need to add any path because their location is already in the search paths. ---------------------------------------------------------------------- marcov · 2014-05-04 16:38 No need for external snippets when windirs.getwindowsspecialdir already abstracts it. ---------------------------------------------------------------------- JanRoza · 2014-05-04 19:40 @marcov: Even better! All those units are so packed with functionality that its hard to discover