解决方案 »
- 日期问题,如何显示本周,切换到上一周,下一周
- 统计网站访问量,同一IP在网页有效期内计数一次,跪求代码!
- 关于获取页面中<title>值
- 51aspx增加了源码在线查看功能,支持高亮折叠
- 九万火急的问题
- 问一个visual studio 的问题,如何实现通过radio 框选中mdb中的字段然后用button读取呢?
- 问一条简单的SQL 语句的写法 在线等 马上结帖子
- 新手上路,ASP.NET应用移植问题,请各位高手帮忙.很急!!!!!!!!!
- 当把文件从服务器发送到客户端时,怎样才不能弹出对话框?
- InnerHtml 的问题
- GridView绑定完自断后怎么添加列
- Jquery页面初始化的问题
{
string str = "";
// Parse the string to check if domain name is present.
int idx = strLogin.IndexOf('\\');
if (idx == -1)
{
idx = strLogin.IndexOf('@');
} string strDomain;
string strName; if (idx != -1)
{
strDomain = strLogin.Substring(0, idx);
strName = strLogin.Substring(idx+1);
}
else
{
strDomain = Environment.MachineName;
strName = strLogin;
}
DirectoryEntry obDirEntry = null;
try
{
Int64 iBigVal = 5;
Byte[] bigArr = BitConverter.GetBytes(iBigVal);
obDirEntry = new DirectoryEntry("WinNT://" +
strDomain + "/" + strName);
System.DirectoryServices.PropertyCollection
coll = obDirEntry.Properties;
object obVal = coll["objectSid"].Value;
if (null != obVal)
{
str = this.ConvertByteToStringSid((Byte[])obVal);
}
}
catch (Exception ex)
{
str = "";
Trace.Write(ex.Message);
}
return str;
}private string ConvertByteToStringSid(Byte[] sidBytes)
{
StringBuilder strSid = new StringBuilder();
strSid.Append("S-");
try
{
// Add SID revision.
strSid.Append(sidBytes[0].ToString());
// Next six bytes are SID authority value.
if (sidBytes[6] != 0 || sidBytes[5] != 0)
{
string strAuth = String.Format
("0x{0:2x}{1:2x}{2:2x}{3:2x}{4:2x}{5:2x}",
(Int16)sidBytes[1],
(Int16)sidBytes[2],
(Int16)sidBytes[3],
(Int16)sidBytes[4],
(Int16)sidBytes[5],
(Int16)sidBytes[6]);
strSid.Append("-");
strSid.Append(strAuth);
}
else
{
Int64 iVal = (Int32)(sidBytes[1]) +
(Int32)(sidBytes[2] << 8) +
(Int32)(sidBytes[3] << 16) +
(Int32)(sidBytes[4] << 24);
strSid.Append("-");
strSid.Append(iVal.ToString());
} // Get sub authority count...
int iSubCount = Convert.ToInt32(sidBytes[7]);
int idxAuth = 0;
for (int i = 0; i < iSubCount; i++)
{
idxAuth = 8 + i * 4;
UInt32 iSubAuth = BitConverter.ToUInt32(sidBytes, idxAuth);
strSid.Append("-");
strSid.Append(iSubAuth.ToString());
}
}
catch (Exception ex)
{
Trace.Warn(ex.Message);
return "";
}
return strSid.ToString();
}http://www.codeproject.com/Articles/3688/How-to-get-user-SID-using-DirectoryServices-classe