// Sample for the Environment.MachineName property
using System;class Sample
{
public static void Main()
{
Console.WriteLine();
// <-- Keep this information secure! -->
Console.WriteLine("MachineName: {0}", Environment.MachineName);
}
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and ed "!---OMITTED---!".)MachineName: !---OMITTED---!
*/
using System;class Sample
{
public static void Main()
{
Console.WriteLine();
// <-- Keep this information secure! -->
Console.WriteLine("MachineName: {0}", Environment.MachineName);
}
}
/*
This example produces the following results:
(Any result that is lengthy, specific to the machine on which this sample was tested, or reveals information that should remain secure, has been omitted and ed "!---OMITTED---!".)MachineName: !---OMITTED---!
*/
解决方案 »
- 关于DATARIDVIEW 如何单击CELL变成COMBOBOX的问题
- 我是用记事本编写的,看看这是什么错误,第一次写C#程序
- c#如何连接Access数据库
- windows 消息 难题
- this.refresh() 和 Application.Doevents()区别
- winform里面怎样让程序重启
- 关于SQL语句与Datagrid的综合使用方面的难题
- 初學C#,可不可以給我一段顯示用C#+access數據庫內容的程序呀.
- 首信易支付接口
- 把一个实例克隆出一个新的实例(副本),有的类提供了copy的方法,但有很多又没有提供,怎么办?
- 请教如何实现页面滚动的位置
- 在应用程序安装完成之后,又接着执行第三方应用程序的安装怎么做啊?
如要取得用户名,用其属性UserName即可,上面的MachineName是取得当前机器名。具体属性查MSDN。下面列举几个常用网络上的属性:
MachineName 获取此本地计算机的 NetBIOS 名称。
UserDomainName 获取与当前用户关联的网络域名。
UserName 获取启动当前线程的人的用户名。当然,该类属于System命名空间,用前请加上using System; 呵呵!
myHost = Dns.GetHostByName(Dns.GetHostName());
MessageBox.Show("aada"+'\r'+myHost.HostName.ToString()+
myHost.HostName);
MessageBox.Show(System.Environment.UserName);
[DllImport("Advapi32.dll", EntryPoint="GetUsername")]
static extern bool GetUserName (stringbuilder str,int ncount)
[DllImport("Advapi32.dll", EntryPoint="GetComputername")]
static extern bool GetComputername (stringbuilder str,int ncount)