How can set the default for user name to be users name/alias from the computer he is accessing the f

G

Gaurav

Hello,

I am creating a infopath form, which has a text field for user to
enter their name/alias.

I would like to prepopulate with the default value of the users
name/alias of the computer where he/she is accessing the form.

Is there a way to do it?

All help is greatly appreciated.

Gaurav
 
J

Josh Bertsch [MSFT]

In JScript:

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;

}

In C#:

System.Security.Principal.WindowsIdentity user =
System.Security.Principal.WindowsIdentity.GetCurrent();

// user.Name holds the current user's DOMAIN\username
// you will have to include 'using System.Security.Principal;'

//or

string strUserName = System.Environment.UserName;


In VBscript:

Sub cmdGetUserName_OnClick(eventObj)
Dim wsh
Set wsh = CreateObject("WScript.Network")
MsgBox wsh.UserName
End Sub

--josh bertsch
 
M

Matthew Blain \(Serriform\)

Note that all of these require elevated trust (full trust for script
solutions, correct settings for .NET). An alternative if your form is
published to a web server is to write a web service which returns the
relevant information, run it on the same server as your form is located.

--Matthew Blain
http://tips.serriform.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top