Retrieving Environmental Details using VB.NET
来源:互联网 发布:学会电脑打字的软件 编辑:程序博客网 时间:2024/04/29 11:37
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
VB.NET removes the complexity of calling API to access such useful information by providing the class library Environment as part of .NET. As known to all of us, the class library is accessible to all the .NET languages.
Here is an example that retrieves the above information using VB.NET.
1) Place a button in the form
2) Place a TextBox in the Form and name it as txtInfo
3) Set the Multi-line property of the TextBox(txtInfo) to True
4) Import the System.Environment namespace
5) Write the following code in the CommandButton click Event
Dim s As String
Dim o As System.Environment
s = "Current Directory=System.Environment.CurrentDirectory()->"
s = s & o.CurrentDirectory() & VBCrLf
s = s & "CommandLine=System.Environment.CommandLine()->"
s = s & o.CommandLine() & VBCrLf
s = s & "Environment Variable=System.Environment.GetEnvironmentVariable(variable)->"
s = s & o.GetEnvironmentVariable("PATH") & VBCrLf
s = s & "MachineName=System.Environment.MachineName->"
s = s & o.MachineName & VBCrLf
s = s & "SystemDirectory=System.Environment.SystemDirectory->"
s = s & o.SystemDirectory & VBCrLf
s = s & "UserName=System.Environment.UserName->"
s = s & o.UserName & VBCrLf
s = s & "UserDomainName=System.Environment.UserDomainName->"
s = s & o.UserDomainName & VBCrLf
s = s & "OSVersion=System.Environment.OSVersion->"
s = s & o.OSVersion.ToString & VBCrLf
txtInfo.Text = s
The namespace System.Environment provides methods to access various information like System Name, Domain Name , Username, OSVersion etc. These methods returns a string as a parameter. Values are retrieved and stored in the local variable s. To avoid using a length qualifier System.Environment with each call, a varaible is declared of type System.Environment and the same is substituted there.
When the button is pressed, all the above information are retrieved and posted in the Textbox txtInfo.
Happy programming with VB.NET.
Details using VB.NET';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
Windows based application would generally have requirement to access the Windows System Directory Path, Current Directory , Windows directory or to retrieve the Current Computer name,UserName, DomainName, OSVersion etc. Retrieving these information required API Calls in VB6.VB.NET removes the complexity of calling API to access such useful information by providing the class library Environment as part of .NET. As known to all of us, the class library is accessible to all the .NET languages.
Here is an example that retrieves the above information using VB.NET.
1) Place a button in the form
2) Place a TextBox in the Form and name it as txtInfo
3) Set the Multi-line property of the TextBox(txtInfo) to True
4) Import the System.Environment namespace
5) Write the following code in the CommandButton click Event
Dim s As String
Dim o As System.Environment
s = "Current Directory=System.Environment.CurrentDirectory()->"
s = s & o.CurrentDirectory() & VBCrLf
s = s & "CommandLine=System.Environment.CommandLine()->"
s = s & o.CommandLine() & VBCrLf
s = s & "Environment Variable=System.Environment.GetEnvironmentVariable(variable)->"
s = s & o.GetEnvironmentVariable("PATH") & VBCrLf
s = s & "MachineName=System.Environment.MachineName->"
s = s & o.MachineName & VBCrLf
s = s & "SystemDirectory=System.Environment.SystemDirectory->"
s = s & o.SystemDirectory & VBCrLf
s = s & "UserName=System.Environment.UserName->"
s = s & o.UserName & VBCrLf
s = s & "UserDomainName=System.Environment.UserDomainName->"
s = s & o.UserDomainName & VBCrLf
s = s & "OSVersion=System.Environment.OSVersion->"
s = s & o.OSVersion.ToString & VBCrLf
txtInfo.Text = s
The namespace System.Environment provides methods to access various information like System Name, Domain Name , Username, OSVersion etc. These methods returns a string as a parameter. Values are retrieved and stored in the local variable s. To avoid using a length qualifier System.Environment with each call, a varaible is declared of type System.Environment and the same is substituted there.
When the button is pressed, all the above information are retrieved and posted in the Textbox txtInfo.
Happy programming with VB.NET.
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- Retrieving Environmental Details using VB.NET
- Environmental Variables using VBA
- Retrieving Database Metadata using C# and .NET
- Retrieving Details for a Contact
- Retrieving Details for a Contact
- vb.net的using用法
- HTMLContentParser ASP.NET Project using VB.NET
- Using System.Configuration.ConfigurationManager Example (VB.NET)
- PasswordSpy - Retrieving lost passwords using Windows hooks
- Retrieving Data Using the SQL SELECT Statement
- Retrieving HTTP content in .NET
- Using PERL,VB.NET,JAVASCRIPT to Resize pictures
- AsyncFileUpload File Type and File Size Validation using VB.NET
- Using VB.NET 2008 DLL as a COM DLL
- ASP.NET: Display GridView Row Details in Modal Popup using Twitter Bootstrap
- .net做UG NX二次开发(VB.net) / NX Secondry Dev. with .net using VB.net Code
- [paper note] Human Re-identification in Crowd Videos using Personal, Social and Environmental (PSE)
- Retrieving HTTP content in .NET - POSTing data
- CREATE TABLE – SQL Command
- webservice系列教学(11)-如何调用webservice(vc2)
- 小写转大写金额
- ASP.NET: SQL DAL Helper
- Google的技术剖析:创始人Sergey Brin 和 Lawrence Pa
- Retrieving Environmental Details using VB.NET
- PFC的使用与探索(一)
- 佳文推荐:运用VB.NET的面向对象的特征
- 程序员的生命
- .NET Framework 之 Common Language Runtime
- 给你个例子[.NET中三层构架开发实例 - 用户注册系统]
- ASP.NET 开发聊天室程序(英文)
- asp.net高级教程(续)
- 触发器介绍