
Download het originele bestand hier

Download het originele bestand hier
Bron:
Mike Taulty's Blog
Welkom op Danny's Smallweb Blog.
Ik (Danny Scheelings) ben één van de vennoten van het mooie bedrijf Smallweb. Deze blog moet een idee geven waar ik zakelijk (en soms ook privé) mee bezig ben.
Onderwerpen die veelal terug zullen komen zijn: softwareontwikkeling, internet, Xbox stuff. Deze laatste is natuurlijk Privé.
Check onze site voor meer informatie over
Smallweb

Download het originele bestand hier

Download het originele bestand hier
Bron:
Mike Taulty's Blog
//Creëer de context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "MijnDomein");
//Creëer een UserPrincipal om te gebruiken voor de Query
UserPrincipal u = new UserPrincipal(ctx);
//Zet de eigenschappen om naar te zoeken
u.GivenName = "Danny";
//Creëer de PrincipalSearcher om mee te zoeken
PrincipalSearcher ps = new PrincipalSearcher(u);
// Voer de Query uit
PrincipalSearchResultresults = ps.FindAll();
public static ListGetGroupUsers(string domainName, string groupName, bool recursive)
{
//Creëer de context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);
//Haal de AD Group op
using (GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(ctx, groupName))
{
//Loop door de Members om de Users te bepalen
Listresult = new List ();
foreach (Principal principal in groupPrincipal.Members)
{
if (principal is UserPrincipal)
result.Add(principal);
}
//Loop door de Members om de Groups recursief te benaderen
if (recursive)
{
foreach (Principal principal in groupPrincipal.Members)
{
//Controleer of de member een Group is
if (principal is GroupPrincipal)
{
//Roep deze methode aan, zodat de recursie ontstaat
foreach (Principal p in GetGroupUsers(domainName, principal.Name, recursive))
{
//geen dubbele Users in de lijst
if (!result.Contains(p))
result.Add(p);
}
}
}
}
return result;
}
}


Hierna was het javascript probleem opgelost en kon ik ook weer netjes een Windows Update uitvoeren.
public const int SRCCOPY = 13369376;
[DllImport("user32.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("User32.dll")]
public static extern IntPtr GetDesktopWindow();
[DllImport("GDI32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);
[DllImport("GDI32.dll")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("GDI32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
[DllImport("GDI32.dll")]
public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
[DllImport("GDI32.dll")]
public static extern bool DeleteDC(IntPtr hdc);
[DllImport("User32.dll")]
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("GDI32.dll")]
public static extern bool DeleteObject(IntPtr hObject);
public static Bitmap CaptureScreen()
{
//In size variable we shall keep the size of the screen.
Point size = Point.Empty;
//Variable to keep the handle to bitmap.
IntPtr hBitmap;
//Here we get the handle to the desktop device context.
IntPtr hDC = GetDC(GetDesktopWindow());
//Here we make a compatible device context in memory for screen device context.
IntPtr hMemDC = CreateCompatibleDC(hDC);
//We pass SM_CXSCREEN constant to GetSystemMetrics to get the X coordinates of screen.
size.X = GetSystemMetrics(0);
//We pass SM_CYSCREEN constant to GetSystemMetrics to get the Y coordinates of screen.
size.Y = GetSystemMetrics(1);
//We create a compatible bitmap of screen size using screen device context.
hBitmap = CreateCompatibleBitmap(hDC, size.X, size.Y);
//As hBitmap is IntPtr we can not check it against null. For this purspose IntPtr.Zero is used.
if (hBitmap != IntPtr.Zero)
{
//Here we select the compatible bitmap in memeory device context and keeps the refrence to Old bitmap.
IntPtr hOld = (IntPtr)SelectObject(hMemDC, hBitmap);
//We copy the Bitmap to the memory device context.
BitBlt(hMemDC, 0, 0, size.X, size.Y, hDC, 0, 0, SRCCOPY);
//We select the old bitmap back to the memory device context.
SelectObject(hMemDC, hOld);
//We delete the memory device context.
DeleteDC(hMemDC);
//We release the screen device context.
ReleaseDC(GetDesktopWindow(), hDC);
//Image is created by Image bitmap handle and stored in local variable.
Bitmap bmp = Image.FromHbitmap(hBitmap);
//Release the memory to avoid memory leaks.
DeleteObject(hBitmap);
//This statement runs the garbage collector manually.
GC.Collect();
//Return the bitmap
return bmp;
}
//If hBitmap is null return null.
return null;
}
private const int MF_BYPOSITION = 0x400;
[DllImport("user32.Dll")]
public static extern IntPtr RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
[DllImport("User32.Dll")]
public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32.Dll")]
public static extern IntPtr GetMenuItemCount(IntPtr hMenu);
/// <summary>
/// Disables the close button of a windows form
/// </summary>
/// <param name="hwnd">The handle of the form.</param>
public static void DisableCloseButton(IntPtr hwnd)
{
//Obtain the handle to the form's system menu
IntPtr menu = GetSystemMenu(hwnd, false);
// Get the count of the items in the system menu
IntPtr menuItemCount = GetMenuItemCount(menu);
// Remove the close menuitem
RemoveMenu(menu, menuItemCount.ToInt32() - 1, MF_BYPOSITION);
}