取得Window系统的当前用户
2012-04-23 14:30
162 查看
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 WindowsApplication25
{
public partial class Form1 : Form
{
[DllImport( "Advapi32.dll ", EntryPoint = "GetUserName ",
ExactSpelling = false, SetLastError = true)]
static extern bool GetUserName(
[MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
[MarshalAs(UnmanagedType.LPArray)] Int32[] nSize);
public Form1()
{
InitializeComponent();
System.Text.StringBuilder b = new System.Text.StringBuilder(100);
int n = b.Capacity;
byte[] str = new byte[256];
Int32[] len = new Int32[1];
len[0] = 256;
GetUserName(str, len);
MessageBox.Show(System.Text.Encoding.ASCII.GetString(str));
string a;
a = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
MessageBox.Show(a.ToString());
}
}
}
The GetUserName function retrieves the name of the user associated with the current thread.(MSDN)
http://topic.csdn.net/u/20070528/15/46630238-b6a0-4d3e-9c6d-a501ac2588e4.html
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 WindowsApplication25
{
public partial class Form1 : Form
{
[DllImport( "Advapi32.dll ", EntryPoint = "GetUserName ",
ExactSpelling = false, SetLastError = true)]
static extern bool GetUserName(
[MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer,
[MarshalAs(UnmanagedType.LPArray)] Int32[] nSize);
public Form1()
{
InitializeComponent();
System.Text.StringBuilder b = new System.Text.StringBuilder(100);
int n = b.Capacity;
byte[] str = new byte[256];
Int32[] len = new Int32[1];
len[0] = 256;
GetUserName(str, len);
MessageBox.Show(System.Text.Encoding.ASCII.GetString(str));
string a;
a = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
MessageBox.Show(a.ToString());
}
}
}
The GetUserName function retrieves the name of the user associated with the current thread.(MSDN)
http://topic.csdn.net/u/20070528/15/46630238-b6a0-4d3e-9c6d-a501ac2588e4.html
相关文章推荐
- C++ 取得系统当前时间
- redhat下查看系统当前登录的用户、更改用户密码、强制踢出用户
- ios开发 获取系统时间 取得当前的年月日,当前的时分秒获得,周几和星期几获得
- 获取当前系统用户是管理员权限还是普通用户权限
- UNIX文件目录管理基本命令之who登录当前系统用户信息
- postgresql查询所有系统表,当前用户,当前时间戳
- 当前程序已使用了 Window 管理器对象的系统允许的所有句柄。
- 判断来访问网站的用户是手机用户还是Web浏览器的用户【即判定用户当前使用的系统】
- XXX 不是当前用户的有效责任,请联系您的系统管理员
- 该帐户当前被锁定,所以用户 'sa' 登录失败。系统管理员无法将该帐户解锁。(Microsoft SQL Server,错误: 18486)
- Linux下用于查看系统当前登录用户信息的4种方法
- 该帐户当前被锁定,所以用户 'service' 登录失败。系统管理员无法将该帐户解锁。
- 有懂discuz的吗?我需要在我自己的系统注册一个账号的时候,也把当前注册的账号放在discuz的用户里面。应该怎么做呀。需要discuz和java的接口吗?需要更改哪些东西。
- 无刷新随时取得用户当前活动信息
- Integrated SOA Gateway 不是当前用户的有效责任。请联系您的系统管理员。
- Linux下用于查看系统当前登录用户信息的4种方法
- Linux下用于查看系统当前登录用户信息的4种方法
- 为当前用户(或普通用户)打开Linux的ifconfig等系统命令
- Jquery对当前系统时间和用户输入时间的比较
- Linux下用于查看系统当前登录用户信息的4种方法