johnllao

July 6, 2009

Using WScript to get user name and domain name in IE

Filed under: Uncategorized — johnllao @ 10:37 am

The following codes show how to retrieve the user name and domain name from javascript code. The follwoing code is quite straight forward however a developer has to consider the following before using this code.

  • The code uses the built-in ActiveX object of IE which of course will only work for IE browsers.
  • Some browser security policies may not allow this implementation as this requires trust settings

    <form id="DefaultForm" runat="server">
        Authenticating user. Please wait...
        <input type="hidden" id="UserName" name="UserName" /><input type="hidden" id="Domain" name="Domain" />
        <script type="text/javascript">//<!--
            var netw = new ActiveXObject("WScript.Network");
            window.document.DefaultForm.UserName.value = netw.UserName;
            window.document.DefaultForm.Domain.value = netw.UserDomain;
            window.document.DefaultForm.submit();
        //-->
        </script>
    </form>

No Comments Yet »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Blog at WordPress.com.