Results 1 to 3 of 3

Thread: [RESOLVED] [02/03] How to use the Environment Class.

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Resolved [RESOLVED] [02/03] How to use the Environment Class.

    Hi All,

    After several hours of research found the way to use the Environment Class.
    Here's my fully code.
    If you want to use it then you need 3 buttons and a ListView.

    VB Code:
    1. Private Sub GetEnvironment_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetEnvironment.Click
    2.         ' set the cursor to an hourglass
    3.         Me.Cursor = Cursors.WaitCursor
    4.         With EnvironmentListView
    5.             ' clear the ListView of any existing items
    6.             .Items.Clear()
    7.             ' Create a ListView variable
    8.             Dim lvi As ListViewItem
    9.             ' Create a new instance of the ListItem variable
    10.             ' and re-use it for each property you add to the ListView
    11.             lvi = New ListViewItem
    12.             With lvi
    13.                 .Text = "Current Directory"
    14.                 .SubItems.Add(Environment.CurrentDirectory)
    15.             End With
    16.             .Items.Add(lvi)
    17.             lvi = New ListViewItem
    18.             With lvi
    19.                 .Text = "Machine Name"
    20.                 .SubItems.Add(Environment.MachineName)
    21.             End With
    22.             .Items.Add(lvi)
    23.             lvi = New ListViewItem
    24.             With lvi
    25.                 .Text = "OS Version"
    26.                 ' NOTE: Call the ToString method to convert the number
    27.                 ' to a string variable for display
    28.                 .SubItems.Add(Environment.OSVersion.ToString)
    29.             End With
    30.             .Items.Add(lvi)
    31.             lvi = New ListViewItem
    32.             With lvi
    33.                 .Text = "System Directory"
    34.                 .SubItems.Add(Environment.SystemDirectory)
    35.             End With
    36.             .Items.Add(lvi)
    37.             lvi = New ListViewItem
    38.             With lvi
    39.                 .Text = "Ticks since last shutdown"
    40.                 .SubItems.Add(Environment.TickCount)
    41.             End With
    42.             .Items.Add(lvi)
    43.             lvi = New ListViewItem
    44.             With lvi
    45.                 .Text = "User Domain Name"
    46.                 .SubItems.Add(Environment.UserDomainName)
    47.             End With
    48.             .Items.Add(lvi)
    49.             lvi = New ListViewItem
    50.             With lvi
    51.                 .Text = "User Name"
    52.                 'Note: Call the ToString method to convert the number
    53.                 ' to a string variable for display
    54.                 .SubItems.Add(Environment.UserName)
    55.             End With
    56.             .Items.Add(lvi)
    57.             lvi = New ListViewItem
    58.             With lvi
    59.                 .Text = "User DomainName"
    60.                 .SubItems.Add(Environment.Version.ToString)
    61.             End With
    62.             .Items.Add(lvi)
    63.         End With
    64.         Me.Cursor = Cursors.Default
    65.     End Sub
    66.  
    67.     Private Sub GetDrives_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetDrives.Click
    68.         ' Set the Cursor to an Hourglass
    69.         Me.Cursor = Cursors.WaitCursor
    70.         ' Clear the ListView
    71.         EnvironmentListView.Items.Clear()
    72.         'Declare a string array called logicalDrivers and call the
    73.         ' GetLogicalDrivers method of the Environment class
    74.         Dim LogicalDrives As String() = Environment.GetLogicalDrives()
    75.         'Create a string variable so we can loop
    76.         'trough the array using For Each
    77.         Dim Drive As String
    78.         'Create a ListView Item variable
    79.         Dim lvi As ListViewItem
    80.         'Look for each drive variable in the logicalDrives string array
    81.         For Each Drive In logicalDrives
    82.             With EnvironmentListView
    83.                 lvi = New ListViewItem
    84.                 With lvi
    85.                     .Text = "Drive Letter"
    86.                     .SubItems.Add(Drive)
    87.                 End With
    88.                 .Items.Add(lvi)
    89.             End With
    90.         Next Drive
    91.         Me.Cursor = Cursors.Default
    92.     End Sub
    93.  
    94.     Private Sub GetSpecialFolders_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetSpecialFolders.Click
    95.         ' set the cursor to an hourglass
    96.         Me.Cursor = Cursors.WaitCursor
    97.         With EnvironmentListView.Items
    98.             'clear the ListViewItems
    99.             .Clear()
    100.  
    101.             ' Add each property into the ListView
    102.             .Add("Program Files Folder").SubItems.Add _
    103.             (Environment.GetFolderPath _
    104.             (Environment.SpecialFolder.ProgramFiles))
    105.             .Add("Application Data").SubItems.Add _
    106.             (Environment.GetFolderPath _
    107.             (Environment.SpecialFolder.ApplicationData))
    108.             .Add("Personal Folder").SubItems.Add _
    109.             (Environment.GetFolderPath _
    110.             (Environment.SpecialFolder.Personal))
    111.             .Add("Local Application Data Folder").SubItems.Add _
    112.             (Environment.GetFolderPath _
    113.             (Environment.SpecialFolder.ApplicationData))
    114.  
    115.         End With
    116.         Me.Cursor = Cursors.Default
    117.     End Sub

    If you like it let me know.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188

    Re: [02/03] How to use the Environment Class.

    it is nice code. what is the difference ebtween
    User Domain Name
    &
    User DomainName <- What is this number result?

    Really a version of something...
    VB 6 / VB.NET 2003, 2005 / Crystal Reports 9-12

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [02/03] How to use the Environment Class.

    Quote Originally Posted by craigreilly
    it is nice code. what is the difference ebtween
    User Domain Name
    &
    User DomainName <- What is this number result?

    Really a version of something...
    Hi,

    The User Domain Name is just the same as the Machine Name and the User DomainName is the network domain name associated with the current user.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width