using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("Advapi32.dll", EntryPoint = "GetUserName", ExactSpelling = false, SetLastError = true)] static extern bool GetUserName(string lpBuffer, ref int nSize); private void Form1_Load(object sender, EventArgs e) { string str ; int len ; len = 20; GetUserName(str, len); MessageBox.Show(str); } } }