By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,214 IT Pros & Developers. It's quick & easy.

Retrieving Environment Variables

P: n/a
Is there a way to retrieve the Windows Environment Variables (Such as
User ID) with Javascript in IE?

Jan 3 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Matt wrote on 03 jan 2006 in comp.lang.javascript:
Is there a way to retrieve the Windows Environment Variables (Such as
User ID) with Javascript in IE?


That would be a security risk, so: No, not in a default setting.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 3 '06 #2

P: n/a
JRS: In article <Xn********************@194.109.133.242>, dated Tue, 3
Jan 2006 20:46:48 local, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Matt wrote on 03 jan 2006 in comp.lang.javascript:
Is there a way to retrieve the Windows Environment Variables (Such as
User ID) with Javascript in IE?


That would be a security risk, so: No, not in a default setting.


It's not necessarily a security risk if the IE is displaying a local
page rather than one obtained from outside (the latter is our default
assumption here).

Javascript running under WSH can read environment variables - see in
<URL:http://www.merlyn.demon.co.uk/batfiles.htm#WSH> - and AIUI the
script engine is shared with IE. So it's conceivable that the OP's
question might be answerable in the affirmative - but I don't know how
to do it.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jan 4 '06 #3

P: n/a
Dr John Stockton wrote on 04 jan 2006 in comp.lang.javascript:
Javascript running under WSH can read environment variables - see in
<URL:http://www.merlyn.demon.co.uk/batfiles.htm#WSH> - and AIUI the
script engine is shared with IE. So it's conceivable that the OP's
question might be answerable in the affirmative - but I don't know how
to do it.


The below is VBS but can be easily translated to wscript-JS:

======== showEnvVar.vbs ===========

set WshShell = CreateObject("WScript.Shell")

set oEnv=WshShell.Environment("System")
for each sitem in oEnv
strval=strval & sItem &vbcrlf
next
wscript.echo "System Environment:"&vbcrlf&vbcrlf&strval
strval=""

'//Process Type
set oEnv=WshShell.Environment("Process")
for each sitem in oEnv
strval=strval & sItem &vbcrlf
next
wscript.echo "Process Environment:"&vbcrlf&vbcrlf&strval
strval=""

'//User Type
set oEnv=WshShell.Environment("User")
for each sitem in oEnv
strval=strval & sItem &vbcrlf
next
wscript.echo "User Environment:"&vbcrlf&vbcrlf&strval
strval=""

'//Volatile Type
set oEnv=WshShell.Environment("Volatile")
for each sitem in oEnv
strval=strval & sItem &vbcrlf
next

wscript.echo "Volatile Environment:"&vbcrlf&vbcrlf&strval
strval=""

===================================

Source: <http://hacks.oreilly.com/pub/h/1107>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 4 '06 #4

P: n/a
Dr John Stockton said the following on 1/4/2006 12:25 PM:
JRS: In article <Xn********************@194.109.133.242>, dated Tue, 3
Jan 2006 20:46:48 local, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Matt wrote on 03 jan 2006 in comp.lang.javascript:

Is there a way to retrieve the Windows Environment Variables (Such as
User ID) with Javascript in IE?


That would be a security risk, so: No, not in a default setting.

It's not necessarily a security risk if the IE is displaying a local
page rather than one obtained from outside (the latter is our default
assumption here).

Javascript running under WSH


Except that Javascript doesn't "run under WSH". JScript does though.

People who live in glass houses shouldn't throw stones at the neighbors.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jan 4 '06 #5

P: n/a
Randy Webb wrote on 04 jan 2006 in comp.lang.javascript:
Dr John Stockton said the following on 1/4/2006 12:25 PM:
JRS: In article <Xn********************@194.109.133.242>, dated Tue, 3
Jan 2006 20:46:48 local, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Matt wrote on 03 jan 2006 in comp.lang.javascript:
Is there a way to retrieve the Windows Environment Variables (Such as
User ID) with Javascript in IE?
That would be a security risk, so: No, not in a default setting.

It's not necessarily a security risk if the IE is displaying a local
page rather than one obtained from outside (the latter is our default
assumption here).

Javascript running under WSH


Except that Javascript doesn't "run under WSH". JScript does though.

People who live in glass houses shouldn't throw stones at the neighbors.


Why not? It would be fun.

Let's meet at Christal Palace, John!

[Or did you hit it in 1854?]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jan 4 '06 #6

P: n/a
JRS: In article <Xn********************@194.109.133.242>, dated Wed, 4
Jan 2006 18:41:19 local, seen in news:comp.lang.javascript, Evertjan.
<ex**************@interxnl.net> posted :
Dr John Stockton wrote on 04 jan 2006 in comp.lang.javascript:
Javascript running under WSH can read environment variables - see in
<URL:http://www.merlyn.demon.co.uk/batfiles.htm#WSH> - and AIUI the
script engine is shared with IE. So it's conceivable that the OP's
question might be answerable in the affirmative - but I don't know how
to do it.


The below is VBS but can be easily translated to wscript-JS:

======== showEnvVar.vbs ===========

I have, at the cited reference, javascript that executed by cscript
(console version of wscript); it does not look equivalent, but simpler.

However, the question of whether such code can be executed successfully
from a local file by javascript in IE remains open.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jan 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.