Jscript and environment variables
Something I though would be simple..
I just want to get a environment variable from inside of a Jscipt script.
The script is being run from a Infopath form.
I saw one way of doing it below
var WshShell = WScript.CreateObject("WScript.Shell");
var wshEnv = WSHShell.Environment("Volatile");
var test = wshEnv("Prompt");
But I get a 'wscript' is undefined error.
Is there a way ro read them directly? without using wscript?
If not how do I get wscript working..
Thanks
[533 byte] By [
ssciarrino] at [2007-11-19 21:07:37]

# 1 Re: Jscript and environment variables
Let me get this straight, you want VBScript to get a JavaScript variable?
# 2 Re: Jscript and environment variables
Jscipt From Microsoft ( http://en.wikipedia.org/wiki/Jscript)
And I want it to get a Environmental variable Like the path or username.
Open a cmmand prompt and type Set.
One of those variables.
Thanks
# 3 Re: Jscript and environment variables
The term JScript is not common anymore, it is known as JavaScript.
You cannot do what you are trying to accomplish because it is a browser scripting language. Everything you do is manipulated in the browser.
You could use ASP or PHP but they will only get environment variables on the server computer and not the local machine that is viewing the server.
# 4 Re: Jscript and environment variables
insted of ..
var WshShell = WScript.CreateObject("WScript.Shell");
try
var wshShell = new ActiveXObject("WScript.Shell");
# 5 Re: Jscript and environment variables
If I fully Trust the Form/code with the 2 different options I get
var wshShell = new ActiveXObject("WScript.Shell");
var wshEnv = WSHShell.Environment("Volatile");
var test = wshEnv("Prompt");
'WSHShell' is undefined in line 2
OR
var WshShell = WScript.CreateObject("WScript.Shell");
var wshEnv = WSHShell.Environment("Volatile");
var test = wshEnv("Prompt");
'WScript' is undefinded in Line 1
THanks
# 6 Re: Jscript and environment variables
JScript .NET is what Microsoft calls it and it is used in InfoPath (part of MS office)
So there is no browser..
# 7 Re: Jscript and environment variables
JScript .NET is what Microsoft calls it and it is used in InfoPath (part of MS office)
So there is no browser..
Then you need to specify that. There is a major difference between JavaScript and JScript .NET. Any .NET technology is pretty new and uses the .NET framework.
Have you tried...
Set oShell = CreateObject("WScript.Shell")
Set oWshProcessEnv = oShell.Environment("process")
WScript.Echo oWshProcessEnv("PROMPT")
# 8 Re: Jscript and environment variables
Then I get this
Expected ';'
File:script.js
Line:52
Set oShell = CreateObject("WScript.Shell");
# 9 Re: Jscript and environment variables
Put semicolons at the end of each line.
# 10 Re: Jscript and environment variables
If I fully Trust the Form/code with the 2 different options I get
var wshShell = new ActiveXObject("WScript.Shell");
var wshEnv = WSHShell.Environment("Volatile");
var test = wshEnv("Prompt");
'WSHShell' is undefined in line 2
OR
var WshShell = WScript.CreateObject("WScript.Shell");
var wshEnv = WSHShell.Environment("Volatile");
var test = wshEnv("Prompt");
'WScript' is undefinded in Line 1
THanks
variable name is case-sensitive..
var wshShell = new ActiveXObject("WScript.Shell");
var wshEnv = wshShell.Environment("Volatile");
var test = wshEnv("Prompt");
# 11 Re: Jscript and environment variables
variable name is case-sensitive..
Yes, but the variable name is PROMPT not Prompt.
# 12 Re: Jscript and environment variables
Thanks This all works now.
So in My login script I search AD and pull out Information and write it to Environmant Variables.
Then in Infopath I can grab them.
But the InfoPath form does have to be fully trusted and Signed.
Here is the Final CODE: THANKS
var wshShell = new ActiveXObject("WScript.Shell");
var wshEnv = wshShell.Environment("PROCESS");
XDocument.DOM.selectSingleNode("/my:myFields/my:Username").text = wshEnv("USERNAME");
XDocument.DOM.selectSingleNode("/my:myFields/my:Email").text = wshEnv("EMAIL");
XDocument.DOM.selectSingleNode("/my:myFields/my:Last_Name").text = wshEnv("LASTNAME");
XDocument.DOM.selectSingleNode("/my:myFields/my:First_Name").text = wshEnv("FIRSTNAME");