Archive for the ‘Uncategorized’ Category

Introduction 
I have written an application for deleting accounts from the Active Directory wrapper.
  1. public static string DelUserInAD(string sGroupName, string strDomain, string strName)
  2.         {
  3.             bool done = false;
  4.             string result = string.Empty;
  5.             try
  6.             {
  7.                 PrincipalContext oPrincipalContext = GetPrincipalContext();
  8.                 string sUserName = strDomain + “\\” + strName;
  9.                 UserPrincipal oUserPrincipal = UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
  10.                 GroupPrincipal oGroupPrincipal = GetGroup(sGroupName);
  11.                 if (oUserPrincipal != null && oGroupPrincipal != null)
  12.                 {
  13.                     if (IsUserGroupMember(sUserName, sGroupName))
  14.                    {
  15.                         //oGroupPrincipal.Members.Add(oUserPrincipal);
  16.                         //oGroupPrincipal.Save();
  17.                         oGroupPrincipal.Members.Remove(oUserPrincipal);
  18.                         oGroupPrincipal.Save();
  19.                         done = !(oUserPrincipal.IsMemberOf(oGroupPrincipal));
  20.                     }
  21.                     else
  22.                     {
  23.                        result = sUserName + ” already exists. Exiting!!”;
  24.                     }
  25.                 }
  26.             }
  27.             catch
  28.             {
  29.             }
  30.             return result;
  31.         }

I have located the following code and have been trying to change this so that I know if the USB device has been inserted or removed.

using System;

using System.Collections.Generic;

using System.Text;

using System.Management;

 

namespace WMIUSBConsolApplication

{

class Program

{

static void Main(string[] args)

{

AddInsetUSBHandler();

AddRemoveUSBHandler();

for (; ; ) ;

}

static ManagementEventWatcher w = null;

public static void AddRemoveUSBHandler()

{

WqlEventQuery q;

ManagementScope scope = new ManagementScope(“root\\CIMV2”);

scope.Options.EnablePrivileges = true;

try

{

q = new WqlEventQuery();

q.EventClassName = “__InstanceDeletionEvent”;

q.WithinInterval = new TimeSpan(0, 0, 3);

q.Condition = @”TargetInstance ISA ‘Win32_USBHub'”;

w = new ManagementEventWatcher(scope, q);

w.EventArrived += new EventArrivedEventHandler(USBRemoved);

w.Start();

}

 

catch (Exception e)

{

 

Console.WriteLine(e.Message);

if (w != null)

w.Stop();

}

}

 

static void AddInsetUSBHandler()

{

WqlEventQuery q;

ManagementScope scope = new ManagementScope(“root\\CIMV2”);

scope.Options.EnablePrivileges = true;

 

try

{

q = new WqlEventQuery();

q.EventClassName = “__InstanceCreationEvent”;

q.WithinInterval = new TimeSpan(0, 0, 3);

q.Condition = @”TargetInstance ISA ‘Win32_USBHub'”;

w = new ManagementEventWatcher(scope, q);

w.EventArrived += new EventArrivedEventHandler(USBAdded);

w.Start();

}

catch (Exception e)

{

 

Console.WriteLine(e.Message);

if (w != null)

w.Stop();

}

}

 

public static void USBAdded(object sender, EventArgs e)

{

Console.WriteLine(“A USB device inserted”);

}

 

public static void USBRemoved(object sender, EventArgs e)

{

Console.WriteLine(“A USB device removed”);

}

}

}

Add a workflow to a site content type :

1. Browse to the site where you want to add a workflow to a content type.

2. In the Site Actions section, click Site Settings.

3. On the Site Settings page under Galleries, click Site content types

Site content types

4. On the Site Content Type Gallery page, in the Site Content Type column, click on the content type to which you want to add a workflow.

Site Content Type column

5. On the Site Content Type page, in the Settings section, click Workflow settings.

Workflow Settings

6. On the Change Workflow Settings page, click Add a workflow.

7. Follow the instructions to configure the workflow instance as noted in the previous procedure, starting with the step 4.