轉自:http://tmsoft.lsxy.com/index.php?load=read&id=224
1.添加引用
2.引用Microsoft.VisualBasic 命名空間
3.所有的My對象應用皆出自以下類庫,本文僅拋磚引玉,更多請大家看MSDN
4.應用-擷取應用程式所在伺服器資訊說明:要添加using Microsoft.VisualBasic.Devices;
代碼
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Microsoft.VisualBasic.Devices.Computer my = new Computer();
TextBox1.Text = "機器名為:" + my.Name + "\r\n";
TextBox1.Text += "作業系統資訊為:" + my.Info.OSFullName +" "+my.Info.OSPlatform+" "+my.Info.OSVersion +"\r\n";
TextBox1.Text += "實體記憶體為:" + my.Info.TotalPhysicalMemory + "\r\n";
TextBox1.Text += "虛擬記憶體為:" + my.Info.TotalVirtualMemory + "\r\n";
TextBox1.Text += "可用實體記憶體為:" + my.Info.AvailablePhysicalMemory + "\r\n";
TextBox1.Text += "可用虛擬記憶體為:" + my.Info.AvailableVirtualMemory + "\r\n"; }
}
5.檔案操作
代碼:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
Microsoft.VisualBasic.Devices.Computer my = new Microsoft.VisualBasic.Devices.Computer();
TextBox1.Text = my.FileSystem.ReadAllText(FileUpload1.PostedFile.FileName,Encoding.GetEncoding("gb2312"));
}
}
6.讀取系統註冊表(這是最粗糙的讀取,建議用遞迴+樹形菜單展示全部)
代碼
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic.Devices;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Microsoft.VisualBasic.Devices.Computer my = new Microsoft.VisualBasic.Devices.Computer();
foreach (String k in my.Registry.CurrentUser.GetSubKeyNames())
{
TextBox1.Text += k + "\r\n";
}
}
}
可以Registry後點出ClassesRoot,LocalMachine等節點請自己嘗試。
7.Microsoft.VisualBasic命名空間的字串處理能力非常強大。
最常見的半形和全形互換,簡體和繁體互換等等做起來非常輕鬆,既然可以這麼輕鬆處理為什麼要寫很複雜的類呢?
代碼:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = Strings.StrConv(TextBox1.Text, VbStrConv.Narrow, 0);
TextBox4.Text = Strings.StrConv(TextBox3.Text, VbStrConv.TraditionalChinese, 0);
}
}
VbStrConv.None |
不執行任何轉換 |
VbStrConv.LinguisticCasing |
使用語言規則進行大小寫,而不使用檔案系統(預設)。僅當與 VbStrConv.UpperCase 和 VbStrConv.LowerCase 一起使用時才有效。 |
VbStrConv.UpperCase |
將字串轉換為大寫字元。 |
VbStrConv.LowerCase |
將字串轉換為小寫字元。 |
VbStrConv.ProperCase |
將字串中每個單詞的第一個字母轉換為大寫。 |
VbStrConv.Wide * |
將字串中的窄(半形)字元轉換為寬(全形)字元。 |
VbStrConv.Narrow * |
將字串中的寬(全形)字元轉換為窄(半形)字元。 |
VbStrConv.Katakana ** |
將字串中的平假名字元轉換為片假名字元。 |
VbStrConv.Hiragana ** |
將字串中的片假名字元轉換為平假名字元。 |
VbStrConv.SimplifiedChinese * |
將繁體中文字元轉換為簡體中文字元。 |
VbStrConv.TraditionalChinese * |
將簡體中文字元轉換為繁體中文字元。 |