Beispiel #1
0
        public void EnumDomains(EnumDomainsDelegate callback)
        {
            int    enumerationContext = 0;
            IntPtr buffer;
            int    count;

            while (true)
            {
                Win32.SamEnumerateDomainsInSamServer(
                    this,
                    ref enumerationContext,
                    out buffer,
                    0x100,
                    out count
                    ).ThrowIf();

                if (count == 0)
                {
                    break;
                }

                using (SamMemoryAlloc bufferAlloc = new SamMemoryAlloc(buffer))
                {
                    for (int i = 0; i < count; i++)
                    {
                        SamSidEnumeration data = bufferAlloc.ReadStruct <SamSidEnumeration>(0, SamSidEnumeration.SizeOf, i);

                        if (!callback(data.Name.Text))
                        {
                            return;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public AppDomainControl(string nativeDllPath)
        {
            IntPtr hDll = LoadLibrary(nativeDllPath);

            IntPtr func = GetProcAddress(hDll, "EnumDomains");

            _enumDomains = (EnumDomainsDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(EnumDomainsDelegate));

            func = GetProcAddress(hDll, "InitializeAppDomain");
            _initializeAppDomain = (InitializeAppDomainDelegate)Marshal.GetDelegateForFunctionPointer(func, typeof(InitializeAppDomainDelegate));
        }
Beispiel #3
0
        public void EnumDomains(EnumDomainsDelegate callback)
        {
            NtStatus status;
            int      enumerationContext = 0;
            IntPtr   buffer;
            int      count;

            while (true)
            {
                status = Win32.SamEnumerateDomainsInSamServer(
                    this,
                    ref enumerationContext,
                    out buffer,
                    0x100,
                    out count
                    );

                if (status >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
                if (count == 0)
                {
                    break;
                }

                using (var bufferAlloc = new SamMemoryAlloc(buffer))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var data = bufferAlloc.ReadStruct <SamSidEnumeration>(i);

                        if (!callback(data.Name.Read()))
                        {
                            return;
                        }
                    }
                }
            }
        }