473,395 Members | 1,466 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,395 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 120112
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.