VB.NET

Operating System and Environments

1. Environment Variables


It is often useful to be able to obtain the values of environmental variables, as well as certain System information. To test the procedures, a LISTBOX named lstOS will be required.
    Private Sub EnvVar()  ' 1. Environment Variables
        ' This procedure examines some of the common
        ' environment variables.
        Dim strVar() As String = {"COMPUTERNAME", "NUMBER_OF_PROCESSORS", _
        "PROCESSOR_IDENTIFIER", "SYSTEMDRIVE", "USERNAME", _
        "USERPROFILE", "windir"}
        Dim strValue As String
        Dim intI As Integer
        For intI = 0 To strVar.Length - 1
            strValue = Environment.GetEnvironmentVariable(strVar(intI))
            lstOS.Items.Add(strVar(intI) & " = " & strValue)
        Next
        lstOS.Items.Add("OS version = " & Environment.OSVersion.ToString)
        'MachineName: Gets the NetBIOS name of this local computer.
        lstOS.Items.Add("MachineName= " & Environment.MachineName)
        'TickCount: A 32-bit signed integer containing the
        '   amount of time in milliseconds that has passed since
        '   the last time the computer was started.
        lstOS.Items.Add("TickCount= " & Environment.TickCount)
        'Working Set: Gets the amount of physical memory mapped
        '      to the process context.
        lstOS.Items.Add("Working Set= " & Environment.WorkingSet)
    End Sub

2. Lauching another Process


A user can start another application within VB.net using the process class.

    Private Sub LaunchProcess()
        Dim procCalc As Process = Process.Start("calc.exe")
        procCalc.WaitForExit(60000) ' wait for one minute
        If procCalc.HasExited Then
            lstOS.Items.Add("Calc has terminated")
        Else
            procCalc.Kill()
            lstOS.Items.Add("Calc was still running and has been terminated")
        End If
    End Sub





Last update: 2004-05-02