Retrieve username from logon environment.

The following is the most common code snippet I offer to people.    The original authors are mentioned in the post below.


INFOPATHFAQ010124 - from the web, can you pass a users login to a form? - 8 Comments - stephencummins - Mon, Aug 18th, 2003 - Development

If the username and password are different from the one the user is currently logged in as, there's no way for InfoPath to access the authentication information. If the username is the same as the currently logged in user, you can use code like this:

function XDocument::OnLoad(eventObj)


//Create a WScript.Network object, which provides access to the user data

var objNetwork = new ActiveXObject("");

//Retrieve the UserName and write it into the my:UserName field


= objNetwork.UserName;

//Retrieve the UserDomain and write it into the my:UserDomain field


= objNetwork.UserDomain;

//Retrieve the ComputerName and write it into the my:ComputerName field


= objNetwork.ComputerName;


NOTE: Internet Explorer's security settings will affect whether you can create and use the WScript.Network object.

Joel Alley


Pasted from <>