[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

List all folders in a directory

Posted on 2006-04-27
4
Medium Priority
?
286 Views
Last Modified: 2010-04-23
Im looking for a program that would be able to list all the folders in Documents and Settings, so I can get a list of users that can log onto a pc.
0
Comment
Question by:tonelm54
4 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16551724
You can use the following to enumerate the directories:

        Dim dir As DirectoryInfo = New DirectoryInfo("C:\Documents and settings")
        For Each d As DirectoryInfo In dir.GetDirectories()
            MessageBox.Show(d.FullName)         '// Full path + Name
            MessageBox.Show(d.Name)             '// Name only
        Next
0
 
LVL 19

Expert Comment

by:Fahad Mukhtar
ID: 16551894
Use the following code to automatically get the SystemDrive and then list all the users in the system

For Each user As String In System.IO.Directory.GetDirectories(Environment.GetEnvironmentVariable("SystemDrive") + "\Documents and Settings")
            Console.WriteLine(System.IO.Path.GetFileName(user))
Next
0
 
LVL 8

Accepted Solution

by:
rfgkev earned 2000 total points
ID: 16552134
this also works for non-english systems (tested on english, german and french systems) where it may be called 'Dokuments' or some such spelling.

        For Each dir As String In System.IO.Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\..\..\")
                Console.WriteLine(System.IO.Path.GetFileName(dir))
        Next
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 16552385
You can also get a list of users on a computer using the following code....

Imports System.Management

Public Class Form1
    Inherits System.Windows.Forms.Form

    '....Form Design Code....

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Domain As String = System.Windows.Forms.SystemInformation.ComputerName 'Gets the current computer's name
        Dim msg As String

        Dim UserQuery As String = "SELECT * FROM Win32_UserAccount WHERE Domain='" & Domain & "'"
        Dim Query As New ManagementObjectSearcher(UserQuery)

        Dim User As ManagementObject
        For Each User In Query.Get()
            msg &= "User name: " & User("Name").ToString() & vbNewLine
        Next

        MessageBox.Show(msg, "List of Users", MessageBoxButtons.OK)

    End Sub
End Class

You'll need to add a reference to System.Management.

Regards,

Wayne
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question