Click here to Skip to main content
15,900,816 members
Home / Discussions / C#
   

C#

 
QuestionWindows service communication` Pin
M. J. Jaya Chitra6-Jun-07 0:05
M. J. Jaya Chitra6-Jun-07 0:05 
AnswerRe: Windows service communication` Pin
ganti.r6-Jun-07 1:02
ganti.r6-Jun-07 1:02 
AnswerRe: Windows service communication` Pin
WillemM6-Jun-07 1:03
WillemM6-Jun-07 1:03 
QuestionRe: Windows service communication` Pin
M. J. Jaya Chitra6-Jun-07 1:09
M. J. Jaya Chitra6-Jun-07 1:09 
AnswerRe: Windows service communication` Pin
Not Active6-Jun-07 1:21
mentorNot Active6-Jun-07 1:21 
AnswerRe: Windows service communication Pin
PavanPareta6-Jun-07 1:24
PavanPareta6-Jun-07 1:24 
AnswerRe: Windows service communication` Pin
kubben6-Jun-07 1:41
kubben6-Jun-07 1:41 
QuestionHow to get the full username? Pin
User 26989675-Jun-07 23:14
User 26989675-Jun-07 23:14 
Hello together,

I have to get the full username. My solution only gets it for local users but I need it also when the user is logged in by a domain account. Has anybody an idea how do get this?

using System;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace UserInfo<br />
{<br />
  public class Program<br />
  {<br />
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]<br />
    public struct USER_INFO<br />
    {<br />
      [MarshalAs(UnmanagedType.LPWStr)]<br />
      public String username;<br />
      [MarshalAs(UnmanagedType.LPWStr)]<br />
      public String password;<br />
      [MarshalAs(UnmanagedType.LPWStr)]<br />
      public String comment;<br />
      [MarshalAs(UnmanagedType.LPWStr)]<br />
      public String fullname;<br />
    }<br />
<br />
    [DllImport("Netapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]<br />
    private extern static Int32 NetUserGetInfo(<br />
      [MarshalAs(UnmanagedType.LPWStr)] String ServerName,<br />
      [MarshalAs(UnmanagedType.LPWStr)] String UserName,<br />
      Int32 level,<br />
      out IntPtr BufPtr);<br />
<br />
    [DllImport("Netapi32.dll", SetLastError = true)]<br />
    static extern Int32 NetApiBufferFree(IntPtr Buffer);<br />
<br />
    public static String GetFullname()<br />
    {<br />
      String retVal = String.Empty;<br />
<br />
      try<br />
      {<br />
        // Create an new instance of the USER_INFO struct.<br />
        USER_INFO objUserInfo = new USER_INFO();<br />
        IntPtr bufPtr; // Because it's an OUT, we don't need to alloc.<br />
        Int32 lngReturn = NetUserGetInfo(Environment.MachineName, Environment.UserName, 10, out bufPtr);<br />
        if (lngReturn == 0)<br />
        {<br />
          objUserInfo = (USER_INFO)Marshal.PtrToStructure(bufPtr, typeof(USER_INFO));<br />
          retVal = objUserInfo.fullname;<br />
        }<br />
        NetApiBufferFree(bufPtr);<br />
        bufPtr = IntPtr.Zero;<br />
      }<br />
      catch (Exception ex)<br />
      {<br />
        Console.WriteLine("GetFullname: " + ex.Message);<br />
      }<br />
      <br />
      return retVal;<br />
    }<br />
<br />
    public static void Main(String[] args)<br />
    {<br />
      Console.WriteLine("Login name: " + Environment.UserName);<br />
      Console.WriteLine("Full username: " + GetFullname());<br />
      Console.ReadLine();<br />
    }<br />
  }<br />
}


Greets
Patrick
AnswerRe: How to get the full username? Pin
ScottM15-Jun-07 23:58
ScottM15-Jun-07 23:58 
QuestionLaunching application through local network from another PC Pin
sgeorgije5-Jun-07 22:10
sgeorgije5-Jun-07 22:10 
GeneralRe: Launching application through local network from another PC Pin
ScottM15-Jun-07 23:52
ScottM15-Jun-07 23:52 
GeneralRe: Launching application through local network from another PC Pin
sgeorgije6-Jun-07 1:11
sgeorgije6-Jun-07 1:11 
GeneralRe: Launching application through local network from another PC Pin
ScottM16-Jun-07 1:32
ScottM16-Jun-07 1:32 
AnswerRe: Launching application through local network from another PC Pin
kubben6-Jun-07 1:44
kubben6-Jun-07 1:44 
Questionboundschecker... Pin
Arish rivlin5-Jun-07 21:50
Arish rivlin5-Jun-07 21:50 
AnswerRe: boundschecker... Pin
Christian Graus5-Jun-07 22:03
protectorChristian Graus5-Jun-07 22:03 
QuestionTo bind a value from DataGridView to textbox Pin
codingrocks5-Jun-07 21:44
codingrocks5-Jun-07 21:44 
AnswerRe: To bind a value from DataGridView to textbox Pin
Seishin#5-Jun-07 21:57
Seishin#5-Jun-07 21:57 
QuestionOCX Question Pin
jason_mf5-Jun-07 21:37
jason_mf5-Jun-07 21:37 
AnswerRe: OCX Question Pin
WillemM6-Jun-07 1:05
WillemM6-Jun-07 1:05 
QuestionTCP or HTTP Pin
amitcoder835-Jun-07 21:23
amitcoder835-Jun-07 21:23 
AnswerRe: TCP or HTTP Pin
Manoj Kumar Rai5-Jun-07 21:33
professionalManoj Kumar Rai5-Jun-07 21:33 
GeneralRe: TCP or HTTP Pin
amitcoder835-Jun-07 21:48
amitcoder835-Jun-07 21:48 
GeneralRe: TCP or HTTP Pin
originSH5-Jun-07 22:24
originSH5-Jun-07 22:24 
AnswerRe: TCP or HTTP Pin
leppie6-Jun-07 3:33
leppie6-Jun-07 3:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.