Sign in to follow this  
Followers 0
residualfail

Populate GUI combobox with folder list

6 posts in this topic

Hello,

I'm writing a little GUI and I've got a GUI created with two combo boxes. I want to populate the combo boxes with a list of local user profiles.

I'm trying to find a script that will scan just the "C:\Documents and Settings" folder, and return a simple list of the local user profile folders to an array (or something a combo box can use). I've seen a few different versions of recursive file and folder listers but I think those are probably more complicated than what I want and I honestly can't make heads or tails of them =p.

If there's a better way to identify the local user profiles on a machine that's fine too. I just assumed this would be the easiest method =/

Thanks for any help you can give me.

-Chris

Share this post


Link to post
Share on other sites



Here's a chunk of code that I made to do that for a program I was building. It will populate the combo box with all of the user profiles that it finds on either a WinXP or above system. It will not include profiles like Administrator, Default User, NetworkService that get included in all default installs of Windows.

#include <File.au3>
#include <Array.au3>
#Region ; this section creates a list that will be entered into the combo box below.
Global $UserList, $X = 0, $aUserList[100]
If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
    $NewOS = True
Else
    $NewOS = False
EndIf
If Not $NewOS Then
    $UserList = _FileListToArray("C:\Documents and Settings", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "NetworkService"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "LocalService"
            Case $UserList[$I] = "Administrator"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
        EndSelect
    Next
    ReDim $aUserList[$X]
Else
    $UserList = _FileListToArray("C:\Users", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "Public"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
        EndSelect
    Next
    ReDim $aUserList[$X]
EndIf
$sUserList = _ArrayToString($aUserList, "|")
#EndRegion ; this section creates a list that will be entered into the combo box below.
Global $GUI = GUICreate("Test", 500, 500)
Global $UserName = GUICtrlCreateCombo("", 40, 130, 170)
GUICtrlSetData(-1, $sUserList)
GUISetState()
While 1
    If GUIGetMsg() = -3 Then Exit
    Sleep(100)
WEnd
1 person likes this

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

That looks like it's going to do exactly what I want, plus it's short and to the point. I'll give it a try as soon as possible. Thanks for your very quick response.

Share this post


Link to post
Share on other sites

Flawless. Works better than I hoped! Thanks again for your help!

Share this post


Link to post
Share on other sites

Glad I could help. Like I said, pulled it out of a script I had written before for the same basic need so just a little tweaking was needed.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
BrewManNH

Took me a few minutes to comprehend why you used Select Case on the code. 

IMHO - its brilliant!

Thanks for sharing.

Noel

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0