VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Produce a list of all PC's users (usernames) based on the profiles folder.

by Chris Huff (2 Submissions)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 5th March 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Produce a list of all PC's users (usernames) based on the profiles folder.

API Declarations


Private objFSO As FileSystemObject
Private objFolders As Folders, objFolder As Folder


Rate Produce a list of all PC's users (usernames) based on the profiles folder.



Private Sub Form_Load()
    Dim sBuffer As String
    Dim strPARENT As String
    
    sBuffer = String(255, 0)
    GetProfilesDirectory sBuffer, 255
    
    strPARENT = StripTerminator(sBuffer)
    Set objFSO = New FileSystemObject
    
    'if path is invalid, exit
    If Not objFSO.FolderExists(strPARENT) Then Exit Sub
 
    ' "seed" the loop
    strPaths = IIf(Right(strPARENT, 1) = "\", strPARENT, strPARENT & "\")

    ' Add subfolders, if any, to array
    Set objFolders = objFSO.GetFolder(strPaths).SubFolders
    For Each objFolder In objFolders
        List1.AddItem objFolder.Name
    Next
    
    Set objFSO = Nothing
    Set objFolders = Nothing
    Set objFolder = Nothing

End Sub

Function StripTerminator(sInput As String) As String
    Dim ZeroPos As Long
    ZeroPos = InStr(1, sInput, Chr$(0))
    If ZeroPos > 0 Then
        StripTerminator = Left$(sInput, ZeroPos - 1)
    Else
        StripTerminator = sInput
    End If
End Function

Download this snippet    Add to My Saved Code

Produce a list of all PC's users (usernames) based on the profiles folder. Comments

No comments have been posted about Produce a list of all PC's users (usernames) based on the profiles folder.. Why not be the first to post a comment about Produce a list of all PC's users (usernames) based on the profiles folder..

Post your comment

Subject:
Message:
0/1000 characters