Just thought I may share a solution I have come up with, this message board as been extremely helpful thus far and I wanted to contribute. Seems no one ever brought up this third option.
The goal to obtain the current username.
Assumptions:
1 - I am working in an Intranet environment and it can be assumed I can use windows integrated security.
2 - The client does not want to use digital signatures.
3 – Making the form fully trusted and having to distribute *.js file is viewed as a deployment issue (they want to leverage SharePoint and not have to install anything extra on a machine).
4 – You are leveraging the custom task pane.
There are three approaches to getting the user name.
1 – You can use Managed Code and use the System.Environment.UserName property to get the current user name.
2 – Use ActiveX to get the current user name (discussed on this forum).
3 – Use HttpContext.Current.Request.Se¬¬rverVariables["LOGON_USER"] in a web service if you are not using anonymous access.
The Managed Code way is very easy but if you are using a custom task pane and making calls between the task pane and your InfoPath form, it will have to be fully trusted. As I mentioned making it fully trusted was not an option.
Using ActiveX is again very simple but the form needs to be fully trusted. You do not need full trust to make calls to the custom task pane and vice versa if you are using script.
Using the third option works well if you can remove anonymous access to your web service.
Jason
http://www.k2distillery.com/