Share via


Create and Delete Local Group Technology Sample

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

This sample demonstrates how to create a local group on a computer, add an existing user to that group, and then delete the group.

Note

This sample uses fictitious values and cannot be run until it is modified with real values.

For information about using the samples, see the following topics:

To customize the sample for your settings

  • Modify the following string variables with real values in the CreateAndDeleteLocalGroup.cs or CreateAndDeleteLocalGroup.vb file, depending on which version of the sample is being built:

    • localComputerName - name of computer on which to create group

    • newGroupName - name of group to create

    • existingUserName - name of user to add to the new group

To build the sample

  1. At a command prompt, navigate to the Technologies\DirectoryServices\CreateAndDeleteLocalGroup directory. Navigate to the CS or VB directory, depending on which version of the sample is being built. For information about required settings and the SDK Command Prompt, see How to: Set Sample Settings.

  2. Type msbuild createanddeletelocalgroup.sln at the command line.

To run the sample

  1. At a command prompt, navigate to the directory that contains the built executable file.

  2. Type createanddeletelocalgroup and press Enter.

Note

This sample is a console application. You must start and run it at a command prompt to view its output.

Remarks

This sample does the following tasks:

  • Creates a local group on the specified computer

  • Adds an existing user to that group

  • Deletes the group that has just been created

This sample demonstrates the use of the following elements of the System.DirectoryServices namespace:

  • How to bind a DirectoryEntry object to a local computer using the WinNT provider

  • How to use the Add method of the Children property collection to add a new group to the list of valid groups

  • How to use the CommitChanges method of the DirectoryEntry object to persist changes to the group to the directory store

  • How to use the Invoke method of the DirectoryEntry object to add an existing user to that group

  • How to use the Remove method of the Children property collection to delete the group