Google Answers Logo
View Question
 
Q: Get the windows login username ( No Answer,   17 Comments )
Question  
Subject: Get the windows login username
Category: Computers > Programming
Asked by: darrensmith-ga
List Price: $50.00
Posted: 01 Jul 2002 04:38 PDT
Expires: 31 Jul 2002 04:38 PDT
Question ID: 35422
I am constructing a simple html form. One of the fields on the form
will be the Name of the person currently accessing that form. I would
like to populate this field automatically by extracting the Username
and surname from the microsoft domain server that the user has logged
into. what is the script needed to do this?

Clarification of Question by darrensmith-ga on 01 Jul 2002 07:33 PDT
Clarification.

The users (All ie 5.5) and server (IIS) are all sitting in the domain.
this is essentially a corporate intranet, not accessed by any outside
users.

Would this make a difference?

Request for Question Clarification by xemion-ga on 01 Jul 2002 09:36 PDT
I can retrieve the username and password, would that suit your
purposes?  Retrieving the surname would be much more difficult and in
my personal experience, the actual first and last name fields of the
user are normally left blank.  Perhaps this is different with your
server.  Is it absolutely necessary to retrieve the surname?  Thanks.

xemion-ga

Request for Question Clarification by lucason-ga on 05 Jul 2002 15:52 PDT
Firstly let me assure you that there is no reason this wouldn't be
possible. Using custom active-X anything is possible as long as the
client is willing to enable security exeptions. Before answering
anything though I would like to know which login you are thrying to
capture.

Lets say the client is logged in on a W2K domain and the web server
accessed is secured on a completely diffrent domain across the
internet. In this case you have 2 unrelated logins. Which one are you
interested in?

Clarification of Question by darrensmith-ga on 08 Jul 2002 00:09 PDT
I have 5000 Users connected to the LAN. All the users login to the
same Domain (MEDSHO), which is a w2k domian server. On the domain I
have an Intranet server, which is w2k running IIS. The users can only
access this server if they have logged into the domain. On the domain
server, we store the login name, password and profiles as usual, but
we also keep the Full name and surname of the user. these are captured
when a login profile is created for the user. So fro every login name
MEDSHO/DARRENS, there will also be the fullname Darren Smith (as an
example). Medsho can not be accessd from the outside world without
directly connecting to the lan / wan. So and Internet (WWW) user
cannot reach the domain unless they dial in to our RAS server.

I know that the following ASP will return the users domain  and name
and print it to the screen.
<%Response.write(Request.ServerVariables("LOGON_USER")) %> 

so in contrast to some of the replys in this question, I dont think it
is entirley impossible.

The application is very simple. When the user goes to the intrant web
site, I would like to print at the to of the screen "Welcome NAME
SURNAME"

Short of exporting the entire domain, and putting it into SQL and
cross referencing with the 
<%Response.write(Request.ServerVariables("LOGON_USER")) %> command and
trying to resolve the surname, I though that these must be a simple
way to do this.

I hope this helps.

Request for Question Clarification by lucason-ga on 09 Jul 2002 12:30 PDT
I could direct you to C++ code for a Active-X DLL which you would need
to install on your server. You could then use this lib in your asp to
get the users full name.

To do this you will need to understand C++ coding and active-X
referencing from VB-script.

Would you exept this as an answer?

Clarification of Question by darrensmith-ga on 19 Jul 2002 00:59 PDT
nymsdeveloper-ga , I dont know who you are, but you are a GENIUS.
Tested the script. It works 100%. How do I close this question with
you getting paid ??
Answer  
There is no answer at this time.

Comments  
Subject: Re: Get the windows login username
From: iaint-ga on 01 Jul 2002 05:59 PDT
 
I suspect this is going to be an impossible task, for the simple
reason that it would break Javascript's security model. The user's
name and domain are automatically set as environment variables in
Windows NT and Windows 2000
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q100843 --
however if the browser had read ability to such information then it
could pass potentially private data back to a server without the user
being aware of it.

To prevent this kind of thing, Javascript (or any other browser
scripting language) is unable to read client system environment
variables.

iaint-ga
Subject: Re: Get the windows login username
From: gopalkamat-ga on 01 Jul 2002 06:03 PDT
 
Hi darrensmith-ga,

As far as my knowledge and research goes regarding HTML, Javascript or
even Server-side Scripting languages, I can say that it is not
possible to extract the NT domain login name for any particular user
over the web.  This, because it would be considered a serious security
breach to allow this to happen.  The only way I think this would be
possible is if the code in your form (mostly Javascript, I think) was
to explore any hacks/exploits discovered in the browser software (IE
or Netscape)... but even as I say this, I know that both these
browsers have come a long way to allow for such hacks/exploits in the
code.

Once again, what you're seeking is not possible in today's world.  If
tomorrow, IE or Netscape released a new version of the browsers with a
hack/exploit in them, then this may be remotely possible.

Hope this helps you out...

regards,
gopalkamat-ga
Subject: Re: Get the windows login username
From: netcrazy-ga on 01 Jul 2002 06:22 PDT
 
I agree with both the above comments. As of today, getting the details
from client's system using Javascript is not possible. You'll need to
make some changes either in your html page to ask the user to enter
the name or something else you'll have to think....

Thanks
netcrazy
Subject: Re: Get the windows login username
From: pboy-ga on 01 Jul 2002 06:35 PDT
 
I agree with all the comments above, it is not possible with a
client-side script.

If you create the HTML form from a server-side script and the server
uses IIS NT authentication ('Integrated Windows Autentication'), you
will get the user name in the AUTH_USER enviroment variable on the
server-side. An ASP or PHP script can insert this user name into the
form generated.
Getting other user information (like real world name) require to
develop a small OLE object in a Win32 native language, e.g. Delphi,
VB, C++.

On client-side, it _may_ be possible with an signed ActiveX control,
but I'm not sure and it is also browser-dependant.

regards,

  pboy-ga
Subject: Re: Get the windows login username
From: pboy-ga on 01 Jul 2002 06:38 PDT
 
Just a little correction on my comment:
On server-side, you don't need to develop an OLE object. ADSI can be used from ASP.
Subject: Re: Get the windows login username
From: wengland-ga on 01 Jul 2002 06:51 PDT
 
Acutally, with IE it may be possible - you'll need a signed fully
trusted script or Active X control.  No idea how to write that, but
it's one tangent you may want to look at.
Subject: Re: Get the windows login username
From: vit-ga on 01 Jul 2002 11:25 PDT
 
Hello,

The best way to do that will be using VB Script.. The reason is that
VB Script is the best to invoke internal controls of Windows OS....I
don't really know how to do that but I can do it using API in Visual
Basic.
The API call needed can be declared as under :

Private Declare Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

But I don't know how you will incorporate this in VB Script. 

Hope this information may help you in some way or the other. But mind
you, how will you get the username of any person surfing your site
through a MAC or UNIX OS????

Warm Regards,

VIT (Vivek Toshniwal)
Subject: Re: Get the windows login username
From: robbienewbie-ga on 01 Jul 2002 13:21 PDT
 
Supporting VIT's comment, you can work with VBScript and VB.
Just create a VisualBasic program that able to see username.
When it works, move it as OCX, which should be usable within
VBScript/HTML.

This way, instead of finding a way to pass HTML/Scripting limitation,
you just need to focus on VisualBasic programming to access those
data.
Subject: Re: Get the windows login username
From: webbob-ga on 01 Jul 2002 21:52 PDT
 
This all sounds like a lot of ways to gain something that should not
(would not) be gained if it was directed at you the answers' team. I
think everyone should rethink where they are coming from on this one.

Besides, there is no way you can get the user’s name, if it does not
exist on their computer. Even if you do get a user’s name, it may be
an alias. Don’t you think, by now, people are sophisticated enough to
understand that there is a computer world and there is a real world?

Who are you trying to kid?
webbob-ga
Subject: Re: Get the windows login username
From: pboy-ga on 02 Jul 2002 00:54 PDT
 
If you accept as answer, I can give you an ASP example in JScript or
VBScript (tested, working).

My solution works only on the server-side (the form must be generated
from ASP code), if IIS use Integration Windows Authentication
(automatically handled by Internet Explorer) and no client
certificates applied to the corporate intranet site.

Retrieving the surname from the user's real name is a little bit
complex task, since no difference is made between first and last names
(AFAIK). If you have a corporate policy for real word user names (e.g.
"Peter, Falk"), surname extraction can be done easily.
Subject: Re: Get the windows login username
From: pboy-ga on 10 Jul 2002 05:35 PDT
 
Is there a real reason to write an OLE object to retrieve the full
user name on server side (ASP) in Windows 2000?
If I understand the circumstaces right, a WMI query can return it from
two lines of ASP code (if you already have the domain user name from
AUTH_USER or LOGON_USER). I already had it working on our intranet,
just some lines of JScript ASP code.
Subject: Re: Get the windows login username
From: pboy-ga on 10 Jul 2002 05:45 PDT
 
Errata: "WMI" should be read as "ADSI". Pardon :)
Subject: Re: Get the windows login username
From: mileshelp-ga on 16 Jul 2002 11:00 PDT
 
Hi,

Since your servers are running Windows 2K, this makes things quite a
bit easier.
Active Directory within Win2K is basically an LDAP database, so can be
queried for the additional information in a similar method.

I'm just trying to put together some sample source to demonstrate this
and will hopefully post it later today.

Hope this helps,
Miles.
Subject: Re: Get the windows login username
From: nymsdeveloper-ga on 16 Jul 2002 19:52 PDT
 
Hi SCRIPT FOR your question
here is a simple page. actually intstead of WinNT(LDAP) ADSI can be
used if available. We do a automatica login in our intranet
application for domain users. discussions here are way off... people
never understood what you were talking about
jai 917 496 4115
<%@ Language=VBScript %>
<HTML>
<HEAD>
<title>Full User name</title>
</HEAD>
<BODY>


<%
	dim strUser ,objUser , sDomain , iPos
    	strUser = trim(Request.ServerVariables ("LOGON_USER"))
	
	if len(strUser) = 0 then
		Response.Write "Unable to find the Login Name. May be not logged to
domain."
		Response.End
	End if 
		Response.write "Login Name:" & strUser 
		iPos = InStr(strUser, "\")
		sDomain = Left(strUser, iPos - 1)
		sUser = Mid(strUser, iPos + 1)

		Set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)
		
%>

<p>
Welcome  <%=objUser.FullName%>
</p>
<%
    set objUser = nothing
%>
</BODY>
</HTML>
Subject: Re: Get the windows login username
From: helium-ga on 17 Jul 2002 17:12 PDT
 
Well, I was about to suggest using ADSI, but it looks like
"nymsdeveloper" has it all wrapped up -- that code will work.  Getting
the user's logon information on a corporate Windows intranet is a
common problem and is easy to solve with Active Directory.  If you
need some further documentation, the following page is a good resource
to what you can do with Active Directory and IIS ...
 "Add to Your ADSI Code Library" (see Section 4.1 for user's full
name)
http://www.15seconds.com/issue/020130.htm

Good luck!
Subject: Re: Get the windows login username
From: nymsdeveloper-ga on 19 Jul 2002 07:04 PDT
 
thank you very much. I am not registered as a researcher, so dont
worry abt payment( i dont think i will get it even if u pay...). if
you need any other help, let me know. my email is
jai@landmark-technologies.com
take care
nymsdeveloper
Subject: Re: Get the windows login username
From: pboy-ga on 29 Jul 2002 03:17 PDT
 
Khm... I have posted the comment about the ADSI solution 6 days before
nymsdeveloper-ga posted his/her comment and I also had a working
script example.
See my comments in the thread. If you'd listen you'd have the code six
days before but you know... :)

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy