nsISupports
Last changed in Gecko 1.7 Implemented by: @mozilla.org/process/environment;
as a service:1
var env = Components.classes["@mozilla.org/process/environment;1"]. getService(Components.interfaces.nsIEnvironment);
void set(in AString aName, in AString aValue); |
AString get(in AString aName); |
boolean exists(in AString aName); |
Set the value of an environment variable.
void set( in AString aName, in AString aValue );
aName
aValue
Get the value of an environment variable.
AString get( in AString aName );
aName
the variable name to retrieve.
Returns the value of the env variable. An empty string will be returned when the env variable does not exist or when the value itself is an empty string - please use exists()
to probe whether the env variable exists or not.
Check the existence of an environment variable. This method checks whether an environment variable is present in the environment or not.
getenv()
returns a non-NULL value. An environment variable does not exist when getenv()
returns NULL.Get()
is empty or not.boolean exists( in AString aName );
aName
If the variable has been set, the value returned is PR_TRUE
. If the variable was not defined in the environment PR_FALSE
will be returned.
This example gets the path to the Porgram Files directory on Windows. Credit to morat from mozillazine.
var nsIEnvironment = Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment);
var pathToProgramFiles = nsIEnvironment
.get("ProgramFiles")
; //for me this returns "C:\Program Files"