Capture the username logged in to Windows by IE 11

Asked

Viewed 251 times

3

I need a code that captures the username logged in to windows. I know it’s possible to do Activex, but only works for versions of IE 7 down.

I am also aware that there are java functions like getProperty() that captures the user name, but needed the code in HTML, Javascript or PHP (provided it captures the information from the user’s machine and not from the server).

Note: The code does not need to run on all browsers, only on IE11 is sufficient.

1 answer

3

According to the documentation of the object Activexobject this object is supported by versions 6, 7, 8, 9 10 and 11 of Intenetexplorer.

//JavaScript
var WinNetwork = new ActiveXObject("WScript.Network");
alert(WinNetwork.UserName);

Here’s the photo of code running on IE11 on Windows 10.

Código sendo executado no IE11

  • @Lipespry: It was good editing, I appreciate it, but if I run the code on the page it goes through a proxy that does not support the object in question.

  • 1

    Yeah, I put it on the snipper only for IE users. If it doesn’t work, it’s fair to take it out of the snippet! Any non-conformity, can revert there in the revision! ;D

  • 1

    It actually works on IE11, but activeX has to be enabled and many users do not have privileges for it (corporate computer). I’m trying to capture by AD, suggestions and ideas are welcome.

  • @Oestudante: I’ve never tried them in server side, but try these commands in PHP <?php echo get_current_user(); ?> and <?php echo getenv("username"); ?>, will that work.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.