Click here to Skip to main content
15,867,568 members
Home / Discussions / C#
   

C#

 
AnswerRe: User List Pin
Randor 25-Mar-20 5:11
professional Randor 25-Mar-20 5:11 
GeneralRe: User List Pin
Richard Andrew x6425-Mar-20 5:33
professionalRichard Andrew x6425-Mar-20 5:33 
GeneralRe: User List Pin
Randor 25-Mar-20 6:10
professional Randor 25-Mar-20 6:10 
GeneralRe: User List Pin
Richard Andrew x6425-Mar-20 6:22
professionalRichard Andrew x6425-Mar-20 6:22 
GeneralRe: User List Pin
Randor 25-Mar-20 8:38
professional Randor 25-Mar-20 8:38 
GeneralRe: User List Pin
Richard Andrew x6425-Mar-20 8:57
professionalRichard Andrew x6425-Mar-20 8:57 
GeneralRe: User List Pin
Randor 25-Mar-20 9:18
professional Randor 25-Mar-20 9:18 
AnswerRe: User List Pin
Randor 25-Mar-20 13:27
professional Randor 25-Mar-20 13:27 
Hmmmm,

You haven't answered yet and since I am under forced quarantine/lockdown orders I threw this together for you. You will have to figure out how to translate it to C#

I apologize in advance for the nested IF statements. It's a code sample and I don't really feel like taking the time to make it look pretty.

C++
// For Richard Andrew x64
//

#pragma comment(lib, "adsiid.lib")
#pragma comment(lib, "Activeds.lib")

#include <iostream>
#include <windows.h>
#include <atlbase.h>
#include <activeds.h>
#include <iads.h>
#include <adshlp.h>
#include <strsafe.h>

INT main()
{
    IADsClass* pClass = NULL;
    IADs* pADs;
    BSTR bstrSchema;
    VARIANT var;
    IEnumVARIANT* pEnumerator = NULL;
    IADsContainer* pContainer = NULL;
    ULONG count;
    IADs* pChild = NULL;
    WCHAR ad_path[MAX_PATH] = { 0 };
    WCHAR computer_name[MAX_COMPUTERNAME_LENGTH] = { 0 };

    count = MAX_COMPUTERNAME_LENGTH;
    GetComputerName(computer_name, &count);
    
    count = MAX_PATH;
    if (SUCCEEDED(CoInitialize(NULL)))
    {
        if (SUCCEEDED(StringCchPrintfW(ad_path, count, L"WinNT://%s,computer", computer_name)))
        {
            if (SUCCEEDED(ADsGetObject(ad_path, IID_IADsContainer, (void**)&pContainer)))
            {
                if (SUCCEEDED(ADsBuildEnumerator(pContainer, &pEnumerator)))
                {
                    VariantInit(&var);
                    while (SUCCEEDED(ADsEnumerateNext(pEnumerator, 1, &var, &count)) && count == 1)
                    {
                        if (SUCCEEDED(V_DISPATCH(&var)->QueryInterface(IID_IADs, (void**)&pChild)))
                        {
                            BSTR bstrClass;
                            pChild->get_Class(&bstrClass);

                            if (CComBSTR(bstrClass) == CComBSTR(L"User"))
                            {
                                IADsUser* user = nullptr;
                                if (SUCCEEDED(pChild->QueryInterface(&user)))
                                {
                                    VARIANT_BOOL is_disabled;
                                    user->get_AccountDisabled(&is_disabled);
                                    if (VARIANT_FALSE == is_disabled)
                                    {
                                        BSTR bstrName;
                                        pChild->get_Name(&bstrName);
                                        std::wcout << bstrName << std::endl;
                                        SysFreeString(bstrName);
                                        pChild->Release();
                                    }
                                }
                            }
                            pChild->Release();
                        }
                        VariantClear(&var);
                    }
                    ADsFreeEnumerator(pEnumerator);
                }
                pContainer->Release();
            }
        }
    }

    CoUninitialize();
    return 0;
}


Best Wishes,
-David Delaune
GeneralRe: User List Pin
Richard Andrew x6425-Mar-20 13:36
professionalRichard Andrew x6425-Mar-20 13:36 
GeneralRe: User List Pin
Richard Andrew x6427-Mar-20 14:37
professionalRichard Andrew x6427-Mar-20 14:37 
QuestionMutlithreading application threading and semaphores? Pin
auting8223-Mar-20 0:52
auting8223-Mar-20 0:52 
GeneralRe: Mutlithreading application threading and semaphores? Pin
Richard MacCutchan23-Mar-20 3:58
mveRichard MacCutchan23-Mar-20 3:58 
GeneralRe: Mutlithreading application threading and semaphores? Pin
auting8223-Mar-20 4:14
auting8223-Mar-20 4:14 
GeneralRe: Mutlithreading application threading and semaphores? Pin
Dave Kreskowiak23-Mar-20 4:36
mveDave Kreskowiak23-Mar-20 4:36 
GeneralRe: Mutlithreading application threading and semaphores? Pin
Richard MacCutchan23-Mar-20 4:41
mveRichard MacCutchan23-Mar-20 4:41 
AnswerRe: Mutlithreading application threading and semaphores? Pin
Gerry Schmitz23-Mar-20 8:05
mveGerry Schmitz23-Mar-20 8:05 
AnswerRe: Mutlithreading application threading and semaphores? Pin
Bohdan Stupak24-Mar-20 1:14
professionalBohdan Stupak24-Mar-20 1:14 
QuestionRDLC printing without print preview Pin
Member 1419221622-Mar-20 21:20
Member 1419221622-Mar-20 21:20 
AnswerRe: RDLC printing without print preview Pin
OriginalGriff22-Mar-20 21:34
mveOriginalGriff22-Mar-20 21:34 
GeneralRe: RDLC printing without print preview Pin
Member 1419221622-Mar-20 21:49
Member 1419221622-Mar-20 21:49 
GeneralRe: RDLC printing without print preview Pin
OriginalGriff22-Mar-20 21:51
mveOriginalGriff22-Mar-20 21:51 
GeneralRe: RDLC printing without print preview Pin
Member 1419221622-Mar-20 22:08
Member 1419221622-Mar-20 22:08 
SuggestionRe: RDLC printing without print preview Pin
Richard Deeming23-Mar-20 0:22
mveRichard Deeming23-Mar-20 0:22 
AnswerRe: RDLC printing without print preview Pin
Gerry Schmitz23-Mar-20 7:49
mveGerry Schmitz23-Mar-20 7:49 
QuestionNotify User From Server Pin
Kevin Marois22-Mar-20 16:11
professionalKevin Marois22-Mar-20 16:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.