65.9K
CodeProject is changing. Read more.
Home

Simple Computer Info.

starIconstarIconstarIconstarIconstarIcon

5.00/5 (5 votes)

Jun 4, 2002

viewsIcon

91840

downloadIcon

935

Get HostName, Logged On User, SytemRoot, Uptime, and a few more with only a few lines of code.

Sample Image - Environment_Class_small.jpg

Introduction

This is the meat of the program. If you need more, then download the project. It's only 25K.

    Public sAppName As String = "Registry Tester"
    Public sRegSection As String = "Startup"
    Public sXpos As String = "StartPos X"
    Public sYpos As String = "StartPos Y"

    Public Sub New()
        MyBase.New()
        Dim X, Y As Integer
        X = GetSetting(sAppName, sRegSection, sXpos, CInt(100))
        Y = GetSetting(sAppName, sRegSection, sYpos, CInt(250))
        Me.Location = New Drawing.Point(X, Y)
        Me.StartPosition = FormStartPosition.Manual
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, _
      ByVal e As System.ComponentModel.CancelEventArgs) _
      Handles MyBase.Closing
        Dim X, Y As Integer
        X = Me.Location.X
        Y = Me.Location.Y
        SaveSetting(sAppName, sRegSection, sXpos, X)
        SaveSetting(sAppName, sRegSection, sYpos, Y)
    End Sub

    Private Sub btnDo_Click(ByVal sender As Object, _
      ByVal e As System.EventArgs) Handles btnDo.Click
        lblOsVersion.Text = Environment.OSVersion.ToString
        lblUser.Text = Environment.UserName.ToString
        lblRuntime.Text = Environment.Version.ToString
        lblUptime.Text = Mid((Environment.TickCount / 3600000), 1, 5) & " :Hours"
    End Sub

    Private Sub btnGetRoot_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles btnGetRoot.Click
        lblSystemRoot.Text = _
            Environment.GetFolderPath(Environment.SpecialFolder.System).ToString
    End Sub

This project started out from reading "Coding Techniques For Visual Basic .NET". But then I got side tracked on the registry to save app settings. And then I got into the Environment class and all of its glory. I have seen a lot of code written to get uptime and so on, but they were a lot more than this. I hope someone likes it.