nsIEnvironment 编辑
xpcom/threads/nsIEnvironment.idl
Scriptable Scriptable access to the current process environment. Inherits from: nsISupports
Last changed in Gecko 1.7Implemented by: @mozilla.org/process/environment;
as a service:1
var env = Components.classes["@mozilla.org/process/environment;1"]. getService(Components.interfaces.nsIEnvironment);
Method overview
void set(in AString aName, in AString aValue); |
AString get(in AString aName); |
boolean exists(in AString aName); |
Methods
set()
Set the value of an environment variable.
void set( in AString aName, in AString aValue );
Parameters
aName
- The variable name to set.
aValue
- The value to set.
get()
Get the value of an environment variable.
AString get( in AString aName );
Parameters
aName
the variable name to retrieve.
Return value
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.
exists()
Check the existence of an environment variable. This method checks whether an environment variable is present in the environment or not.
Note: * For Unix/Linux platforms we follow the Unix definition: An environment variable exists whengetenv()
returns a non-NULL value. An environment variable does not exist when getenv()
returns NULL.- For non-Unix/Linux platforms we have to fall back to a "portable" definition (which is incorrect for Unix/Linux!!!!) which simply checks whether the string returned by
Get()
is empty or not.
boolean exists( in AString aName );
Parameters
aName
- The variable name to probe.
Return value
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.
Examples
Windows
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论