从Firefox扩展中查找当前登录的用户 [英] Finding the currently logged in user from a Firefox extension

查看:144
本文介绍了从Firefox扩展中查找当前登录的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Firefox扩展,需要知道当前登录用户的用户名是在Windows,Mac或Linux上。所以如果我以brh的身份登录我的机器,它将返回brh。任何想法如何从扩展JavaScript中做到这一点?

解决方案

Firefox扩展按照不同的规则,

打开您的错误控制台(在工具中)并输入:

<$ p $ Component.classes [@ mozilla.org/process/environment;1\"].getService(Components.interfaces.nsIEnvironment).get('USER')
NsIEnvironment XPCOM组件。



您可能必须对每个平台进行自定义。如果一切都失败了,您可以在中创建一个 NsIFile 然后看看它的 .path ;我不确定shell表达式是否被尊重,但是...


I'm writing a Firefox extension that needs to know what the username of the currently logged in user is in Windows, Mac, or Linux. So if I'm logged into my machine as "brh", it'll return "brh". Any idea how to do that from extension JavaScript?

解决方案

Firefox extensions play by different rules to normal JavaScript running in the page: finding the current user is absolutely possible.

Open your Error Console (in Tools) and enter this:

Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USER')

The environment variables Firefox was started with are available through that NsIEnvironment XPCOM component.

You may have to customise this per platform. If all else fails, you might be able to create an NsIFile in ~ then look at its .path; I'm not sure if shell expressions are honoured there, though...

这篇关于从Firefox扩展中查找当前登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆