473,320 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to get windows username using javascripts?

Hi.,
i dont know how to get windows username using javascript..
can someone help me please..

thank you in advance,
Mar 14 '07 #1
16 120045
acoder
16,027 Expert Mod 8TB
Welcome to TSDN.

Javascript is for the client-side browser scripting. It shouldn't have anything to do with the operating system. That would be a huge security hole if Javascript could access the Windows username.
Mar 14 '07 #2
Hi.,
It's possible to access the windows username using javascripts.
but i dont know that.
can anybody help me please.
Mar 15 '07 #3
acoder
16,027 Expert Mod 8TB
How can you be so sure it's possible unless you've seen it? Show me an example.

The only possibility I can think of is through ActiveX (if even that).
Mar 15 '07 #4
NeoPa
32,556 Expert Mod 16PB
I'm afraid I know nothing about Javascript (except that I would guess there is some similarity to Java ;)) but I do know that the Windows Username is always set in the environment variable "USERNAME". That may help if you have access to the environment in your Javascript code.
PS. As environment variables are amendable by the user, this is not a 100% reliable way to get this but it works fine in most circumstances.
Oct 4 '07 #5
gits
5,390 Expert Mod 4TB
hi ...

i'm with acoder ... you cannot and should not be able to retrieve things that are outside of the browser with standard-javascript. imagine a website that is able to collect such information while you visit it ... nobody wants that ... however: in case you have an evironment that should allow that ... may be an intranet ... then you may give the browser some privileges (activeX or some advanced mozilla privileges) to retrieve such information ... but in a webenvironment where you cannot control browsers, nor the version, nor the privileges or security settings etc. ... you cannot do that ...

kind regards
Oct 4 '07 #6
NeoPa
32,556 Expert Mod 16PB
Sorry guys.
If you think my post is inappropriate then please feel free to delete it. This is not my area of expertise so I may have stumbled in where I shouldn't have.
Oct 4 '07 #7
acoder
16,027 Expert Mod 8TB
I'm afraid I know nothing about Javascript (except that I would guess there is some similarity to Java ;))
JavaScript was named after Java, but otherwise they're very different. See, for example, History and naming.
Oct 4 '07 #8
gits
5,390 Expert Mod 4TB
hi NeoPa,

nope ... your post is not :) ... as we said ... there is no standard way to retrieve such information with javascript ... but according to specific circumstances it may be possible of course. when using IE's activeX controls you may do everything in case you have control to the browsers security settings ... because activeX-controls can break out of the browsers javascript-sandbox since they might be written in every language that support to create an activex-control, so that such a control might get access to everything at your machine out of a webpage. this could be a good idea when creating intranet-applications for example.

kind regards
Oct 4 '07 #9
NeoPa
32,556 Expert Mod 16PB
JavaScript was named after Java, but otherwise they're very different. See, for example, History and naming.
Thanks for that acoder.
I've used VBA and a little VBScript. They ARE similar. I'd just assumed the relationship was similar for Java & JavaScript.
Oct 4 '07 #10
acoder
16,027 Expert Mod 8TB
Thanks for that acoder.
I've used VBA and a little VBScript. They ARE similar. I'd just assumed the relationship was similar for Java & JavaScript.
Don't worry, you're by no means the first. The naming was unfortunate. Apparently, Java was the buzz word at the time.

The Java forum get a lot of threads regarding JavaScript problems which get transferred here with r035198x's standard response:
Java != Javascript
Oct 4 '07 #11
Hi All,

Firstly, let me agree that this functionality would be a security risk. However if you're a domain/system admin and it's for a local site or a site you have admin access to, it may be possible.

I'm looking into possible ways of doing this myself for auto-authentication on an intranet.

I have a couple of possible solutions, but both have problems. I'll let you know if I come up with something better, but these ideas may help others come up with something.

Solution 1:
Use an ActiveX control, or try to get a visual basic script in a page to get the environment variable.

Problems: Cross browser compatibility - it only works in internet explorer (this won't work in Firefox for example). Also, you need to click the toolbar up the top to allow the control to work. I don't like these. One of my software/system key design principles is "the user is stupid". Based on this principle, assume the user either won't click that toolbar, or will click block.

Solution 2:
Write a cookie from Windows when the user logs in with the user's details, then get the web page retrieve the data from that cookie.

Problems:
Cross browser and operating system issues. Firefox has cookies in a different location to IE etc. Even worse, Firefox on Vista even has a different location to Firefox on XP etc. And just when you get it working, something new will come out to mess it all up again. Also, some users may put cookie restrictions on, which may cause issues.

Any thoughts? I'll keep thinking of ways to do it, but a different approach to whatever the problem is may be best.

Chris Fry
Oct 15 '07 #12
gits
5,390 Expert Mod 4TB
hi ...

in case it is an intranet-environment and you could have control to the browsers and its security settings and restrict them to your needs ... then you simply should support only one solution, lets say the IE version with activeX. you may try to get enhanced mozilla privilegs too, therefore you must edit the about:config and allow mozilla to access os things, probably you need a security certificate at the serverside etc. ... but in case you want the users to have whatever browser they want and whatever security-settings they want ... i think you will have more problems then leaving it as it is ... with a seperate intranet-login i guess. users that want to be logged in with ther windows auth 'should' use 'your' browser ... and the ohers have to re-login ... you cannot have a generic way ... since every browser uses its own specifics ... what about opera? ... or safari? ... in case you could restrict to the use of a specific browser you may have luck with your approach ... in case you could not ... then i think it will be a neverending story ...

kind regards
Oct 15 '07 #13
Try this,
Its should work

var wshshell=new ActiveXObject("wscript.shell");
var username=wshshell.ExpandEnvironmentStrings("%usern ame%");
Oct 15 '07 #14
NeoPa
32,556 Expert Mod 16PB
Try this,
Its should work
Expand|Select|Wrap|Line Numbers
  1. var wshshell=new ActiveXObject("wscript.shell");
  2. var username=wshshell.ExpandEnvironmentStrings("%username%");
Bear in mind that while %USERNAME% is fine for simple identification (Hello Mr Jones), it shouldn't generally be used for security purposes. Very few users are so computer illiterate nowadays that they don't know how to change an environment variable, which is all it takes to confuse that code into treating you as an adminstrator or the company CEO.
*EDIT*
Actually they are not as rare as that. Nevertheless, this method should be treated with caution as there is a fairly straightforward method to beat it.
Oct 15 '07 #15
Eldann
1
Far too late to help abhishekitb, but it can be used by somebody else who asks the same question.

Even if environment variables work well, as NeoPa said, this works too :
Expand|Select|Wrap|Line Numbers
  1. var ActX=new ActiveXObject("wscript.network");
  2. alert(ActX.username);
Note that in the same way, you can get the computer and the domain name.
Expand|Select|Wrap|Line Numbers
  1. alert(ActX.computername);
  2. alert(ActX.userdomain);
Tested on IE... 8... !!!, under Windows XP (sorry, nothing else at hand atm).
Mar 28 '14 #16
NeoPa
32,556 Expert Mod 16PB
People find these threads all the time Eldann, so abhishekitb not benefiting isn't the end of the world. Still worth posting :-)
Mar 29 '14 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Newbie | last post by:
I am a newsbie to ASP but need to get a script together that will insert the Windows Username of the local machine into an access database. I get the errors from my code below, can anyone help me...
8
by: Raj Thakkar | last post by:
Hi, I am currenty working on a site for intranet. I have a user control in the header of every page that will be displayed only if people with certain username are surfing the site. These lists...
5
by: nikou_70 | last post by:
I have a problem with ("auth_user") in asp,I try to use windows username and password in asp page for limitation user access to pages, but this server variable returns empty string, can you help me...
8
by: Bruno Barros | last post by:
Hey there. I'm currently working on an intranet, and would like to know how I can get the windows usernames of the visitors. You can get their IP with $_SERVER; But what about their Windows...
1
by: Ale | last post by:
how can i connect to the database using javascripts?...First of all...is it possiible to connect to the database(SQL/oracle/MySQL/..)
1
by: vickygoelk | last post by:
Hey my question is how we disable the firefox drag feature using javascripts?. if it possible then please solve this problem. Thanks, vivek Kumar
4
by: orajat | last post by:
hi, I'm trying to pull the windows username with jscript and save it to ms access field in a table, but it does not work. it does show the alert with the name of the user but does not save it to...
8
by: tiijnar | last post by:
Hi, To get windows username Im using the following code. public class GetWindowUsername { public String getUser() { String userName = System.getProperty("user.name");...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.