Got this question last week and found out you can get the windows user information into your Flex application. I’m not sure why you would wanna do this
But just for anyone trying to figure this out … here is how to do it.
Through javascript you can get the user Id (This only works through Internet Explore !), so by using ExternalInterface in Flex you can call the javascript function that will get you the user id.
So first you wanna add the javascript to your index.template.html (in html-template folder of your flex builder project). Add the script to the script tag just below the body tag.
var wshShell = new ActiveXObject(“WScript.Shell”);
function getUserName()
{
return wshShell.ExpandEnvironmentStrings(“%USERNAME%”);
}
Then you can add to your MXML application this code to get the user id …
try {
var name:String = ExternalInterface.call(‘getUserName’);
Alert.show(“name = ” + name);
} catch (error:SecurityError) {
Alert.show(“A SecurityError occurred: ” + error.message + “\n”);
} catch (error:Error) {
Alert.show(“An Error occurred: ” + error.message + “\n”);
}
} else {
Alert.show(“External interface is not available for this container.”);
}
}
So as I said … it will only work on Internet Explore. Through the wshShell object you can also get the domainname if needed.
March 26, 2008 at 7:42 pm |
We are developing internal applications with Flex, these internal applications need to get the user name automatically from windows we are using IIS as the web server and we are using windows authentication on the web server is there any way to pull the user name from the web server instead using the CGI environmental variables? Is there a way to access the CGI environemtal variable using Flex?
August 25, 2008 at 4:18 pm |
I am getting a “Automation server can’t create object” when I run the line:
wshShell = new ActiveXObject(“WScript.Shell”);
do you know of any reason for this?
Regards,
Jordan
January 4, 2009 at 7:37 pm |
yes I get the same error. I altered the settings of IE.
Tools > Internet options > Security > Custom Level
Under the ActiveX controls and plug-ins, select Enable for Initializing and Script ActiveX controls not marked as safe.
June 2, 2009 at 8:59 pm |
What is to prevent someone from impersonating another user by doing something such as:
C:\Documents and Settings\me>echo %USERNAME%
me
C:\Documents and Settings\me>set USERNAME=you
C:\Documents and Settings\me>echo %USERNAME%
you
June 20, 2009 at 7:41 pm |
My friend on Facebook shared this link and I’m not dissapointed that I came to your blog.
p.s. Year One is already on the Internet and you can watch it for free.