次の方法で共有


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.

https://www.infopathfaq.com

 

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("WScript.network");

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

XDocument.DOM.selectSingleNode("/my:myFields/my:UserName").text

= objNetwork.UserName;

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

XDocument.DOM.selectSingleNode("/my:myFields/my:UserDomain").text

= objNetwork.UserDomain;

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

XDocument.DOM.selectSingleNode("/my:myFields/my:ComputerName").text

= objNetwork.ComputerName;

}

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

Joel Alley

 

Pasted from <https://www.infopathfaq.com/development.asp?postid=710>

Comments

  • Anonymous
    April 27, 2006
    What other info can you get from objNetwork?