Mega Code Archive

 
Categories / Delphi / Examples
 

How to modify the path variable

Use the following simple function .. E.g. like this: SetSystemEnvironmentVariable ('PATH', 'c:\windows;c:\programs\myapp'); procedure SetSystemEnvironmentVariable (const name, value : string); var rv : DWORD; begin with TRegistry.Create do try RootKey := HKEY_LOCAL_MACHINE; OpenKey ('SYSTEM\CurrentControlSet\Control\SessionManager\Environment', False); WriteExpandString (name, value); SendMessageTimeout (HWND_BROADCAST, WM_SETTINGCHANGE, 0, LParam (PChar ('Environment')), SMTO_ABORTIFHUNG, 5000, rv); finally Free end end;