Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference: Environment Variables & Registry Keys

What is the difference between a Registry Key & an Environment Variable?

I think Environment Variables are only something found in windows OS? And I hear thats its very easy to change these so its not good to trust them? Are Registry Keys just as easy to change?

Are Registry keys stored in the kernal?

My most important question is: I know that the environment variables let me know the path to %APPDATA, the current users name, the path to program files, the version of Windows OS running, etc. BUT do the Registry keys also contain this kind of data - can I also find out this information by looking at the registry keys?

like image 974
user593747 Avatar asked Sep 03 '26 07:09

user593747


1 Answers

Both are used to configure programs. The biggest difference is that environment variables are stored in memory, registry keys are stored in a file. Which explains many of their properties:

  • Environment variable values are lost as soon as the process that writes them terminates.
  • A process cannot update the environment variable values of another process. With one important exception: the environment for a process is created by the process that starts it. The lpEnvironment argument of CreateProcess(). This is how a parent process configures the child processes it starts.
  • The space for storing environment variables is severely limited, 64KB max.
  • Environment variables do not have user scope like registry keys do, they'll have the same value for any user, unless the parent process takes care of it explicitly.
  • Environment variable values cannot be secured.
  • Accessing environment variables is fast. With the caveat that searching for a variable is an O(n) operation since they don't have a hierarchical organization nor an index. The limited environment size makes that unnecessary. Windows heavily optimizes registry key access however.
like image 61
Hans Passant Avatar answered Sep 05 '26 21:09

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!