Sunday, June 28, 2009

Windows Forms - Find all information about Computer

The NameSpace System.Environment is used to get all information about a computer.

The following Code Snippet is used to retrieve the following information about the computer.

1. User Name

2. Machine Name

3. Domain Name

4. System Root Directory

5. Current Directory

6. Logical Drives of the System

7. Version of Operating System

8. Command Line


1. Imports System.Environment

2. Drag and Drop a Label on the form and name it as lblComputerDetails

3. Drag a RichTextBox and drop on the form and name it as txtComputerDetails

4. Drag and Drop a Button on the form and name it as btnDisplayDetails

5. Click On the Button

Private Sub btnDisplayDetails_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles btnDisplayDetails.Click


lblComputerDetails.Text = "Computer Details"

'User Name

txtComputerDetails.Text = "UserName: " & Environment.UserName.ToString & Environment.NewLine

'Computer Name

txtComputerDetails.AppendText("Computer Name: " & Environment.MachineName.ToString & Environment.NewLine)

'Domain Name

txtComputerDetails.AppendText("Domain Name: " & Environment.UserDomainName.ToString & Environment.NewLine)

'System root directory

txtComputerDetails.AppendText("Root Directory: " & Environment.SystemDirectory.ToString & Environment.NewLine)

'Current Directory

txtComputerDetails.AppendText("Current Directory: " & Environment.CurrentDirectory.ToString & Environment.NewLine)

'logical drives

txtComputerDetails.AppendText("Logical Drives: " & Environment.NewLine)

For i As Integer = 0 To Environment.GetLogicalDrives.Length - 1




'Version of operating system

txtComputerDetails.AppendText("Operating System Version: " & Environment.OSVersion.ToString & Environment.NewLine)

'Command Line

txtComputerDetails.AppendText("Command Line: " & Environment.CommandLine.ToString & Environment.NewLine)

End Sub

No comments:

Post a Comment