www.webdeveloper.com
Results 1 to 10 of 10

Thread: Check current username from Windows?

  1. #1
    Join Date
    Nov 2006
    Location
    Ekenäs, Finland
    Posts
    17

    Check current username from Windows?

    Hey guys,

    I'm wondering if this is somehow possible to do using JavaScript (or something else?):

    When a user comes to my website, a (js)script checks what username (as in user account) the user is logged in with in Windows and stores the username in a variable.
    The server used is Apache (if it matters...)

    (This project is for a company's internal use only, it's not going to be online for everyone.)

    I know this might be a stupid question, but please let me know. All I know is that a guy did this sort of script using ASP.

    Thanks in advance!

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    Not with JavaScript, but you can with vbscript.
    Here is an example:
    Code:
    <script type="text/vbscript">
    dim wsh
    set wsh = createobject("WScript.Network")
    login_name = wsh.UserName
    document.write(login_name)
    </script>

  3. #3
    Join Date
    Nov 2007
    Posts
    316
    Untested:
    Code:
    var wshshell=new ActiveXObject("wscript.shell");
    var username=wshshell.ExpandEnvironmentStrings("%username%");

  4. #4
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by TheRave
    Untested:
    Code:
    var wshshell=new ActiveXObject("wscript.shell");
    var username=wshshell.ExpandEnvironmentStrings("%username%");
    Only works if you only have IE users. Same for the VBScript. All the company using IE?

  5. #5
    Join Date
    Nov 2006
    Location
    Ekenäs, Finland
    Posts
    17
    Nope, I'd rather use something that works in FF

  6. #6
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by rade
    Nope, I'd rather use something that works in FF
    Not possible I think, but try the ActiveX solution. It just might work.

  7. #7
    Join Date
    Nov 2006
    Location
    Ekenäs, Finland
    Posts
    17
    I tried both TheRave's and bathurst_guy's codes but neither worked on either FF or IE.

    Please, if anyone has any ideas on how to get this working I would much appreciate it.

    And thanks for your replies guys though I couldn't get them working.

  8. #8
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    I tested mine before posting and it worked for me, but I received a security warning. Nothing like this will work in FF. Only insecure IE. What version of IE are you using. You might need to adjust your security settings to allow it to run.

  9. #9
    Join Date
    Nov 2006
    Location
    Ekenäs, Finland
    Posts
    17
    Quote Originally Posted by bathurst_guy
    I tested mine before posting and it worked for me, but I received a security warning. Nothing like this will work in FF. Only insecure IE. What version of IE are you using. You might need to adjust your security settings to allow it to run.
    I'm using IE7. Which settings do you think I should change?

    This is what I tested, anything I misunderstood?:
    HTML Code:
    <html>
    <head>
    </head>
    <body>
    
    <script type="text/vbscript">
    dim wsh
    set wsh = createobject("WScript.Network")
    login_name = wsh.UserName
    document.write(login_name)
    </script>
    
    </body>
    </html>

  10. #10
    Join Date
    Aug 2007
    Posts
    3,767
    Your security setting are too high. Even IE has finally realised that users don't want that much information about themselves totally accessible.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles