Forum Moderators: open

Message Too Old, No Replies

Detecting logged on Windows user

can this be done with js?

         

HelenDev

1:15 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is it possible to detect the currently logged on windows username with js, or can it be done with some other sort of scripting?

penders

11:30 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



AFAIK this can only be done with an Installed ActiveX control (in IE), or possibly a Java applet...?

It would certainly be a breach of security if JS was able to do this.

HelenDev

12:48 pm on Sep 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Penders, after some further reading I thought that might be the case.

I was just wondering how that's done in applications like Intranets where it welcomes users by name based on the windows logon, maybe it is only with ActiveX / Java as you say.

Trace

4:27 pm on Sep 6, 2007 (gmt 0)

10+ Year Member



There are several ways to get the domain user with some server-side scripting but I don't know of any way to get the windows user.

Example in classic ASP:
<% Response.Write(Request.ServerVariables("AUTH_USER")) %>

This will display: YOUR DOMAIN\YOUR LOGON NAME

XtendScott

4:32 pm on Sep 6, 2007 (gmt 0)

10+ Year Member



usually it would be done server side.

In .asp it is like:
vUser = request.ServerVariables("LOGON_USER")

HelenDev

8:16 am on Sep 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the replies guys.

Any way to do this with PHP?

I know I can do $_SERVER['PHP_AUTH_USER'] but that requires the user to login.

Receptional Andy

9:47 am on Sep 7, 2007 (gmt 0)



It can be done with javascript, but it does require specific activex permissions:

<script type="text/javascript">
<!--
var WinNetwork = new ActiveXObject("WScript.Network");
alert(WinNetwork.UserName);
//-->
</script>

HelenDev

10:42 am on Sep 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Excellent, very cool, that's exactly the kind of thing I was after!

Thanks Andy :)

I see that this only works in IE. I don't know much about activex but I assume it's just an IE thing?

Is it possible to do in Firefox at all?

Receptional Andy

10:45 am on Sep 7, 2007 (gmt 0)



ActiveX will only work in IE (or you can get a plugin for Firefox I believe, although very few will have it installed).

Generally speaking, this type of js is only suitable for intranets and similar kinds of usage where you can know what is installed and/or set security permissions appropriately. IE will quite rightly block access to this by default.

penders

1:21 pm on Sep 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It can be done with javascript...

The results are merely being returned to JavaScript (or whatever client side scripting language you are using), it is the ActiveX Object which is doing all the work in this instance.