Managing Users and Groups Using WMI in Visual Studio .NET

Paint Code 3/9 in Visual Studio .NET Managing Users and Groups Using WMI
Managing Users and Groups Using WMI
Code 3 Of 9 Creator In .NET
Using Barcode creator for .NET framework Control to generate, create Code 39 image in VS .NET applications.
The options for user administration with WMI are unfortunately rather limited ADSI or SystemDirectoryservices offer a lot more, as you will see in the following chapters However, for the sake of completeness, this chapter discusses the options you have within WMI The following command displays an object list of the local users and groups:
Reading Code 39 Extended In .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
Get-WmiObject Win32_Account
Print Bar Code In .NET Framework
Using Barcode maker for Visual Studio .NET Control to generate, create barcode image in Visual Studio .NET applications.
Only user accounts are displayed with the following:
Barcode Recognizer In .NET Framework
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET framework applications.
Get-WmiObject Win32_UserAccount
Encoding Code 39 In Visual C#.NET
Using Barcode creation for .NET Control to generate, create Code39 image in VS .NET applications.
SystemDirectoryServices and the ADSI Adapter
Drawing Code-39 In Visual Studio .NET
Using Barcode drawer for ASP.NET Control to generate, create ANSI/AIM Code 39 image in ASP.NET applications.
Only groups are displayed with this:
Encoding USS Code 39 In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create Code 39 Extended image in Visual Studio .NET applications.
Get-WmiObject Win32_Group
EAN / UCC - 14 Creator In .NET Framework
Using Barcode creator for .NET Control to generate, create EAN128 image in Visual Studio .NET applications.
Of course, you can also lter objects distinctly:
Data Matrix Creation In .NET Framework
Using Barcode printer for .NET Control to generate, create Data Matrix ECC200 image in .NET applications.
# Name and domain of those user accounts whose password never expires Get-WmiObject Win32_useraccount | Where-Object {$_Passwordexpires -eq 0 } | Select-Object Name,Domain
Generate Code 128A In Visual Studio .NET
Using Barcode generator for .NET Control to generate, create ANSI/AIM Code 128 image in Visual Studio .NET applications.
Alternatively, you can use this form:
GS1 - 13 Drawer In .NET
Using Barcode creator for VS .NET Control to generate, create UPC - 13 image in Visual Studio .NET applications.
Get-WmiObject Win32_Useraccount - lter "Passwordexpires='false'" | Select-Object Name,Domain
Painting USPS Intelligent Mail In VS .NET
Using Barcode creation for .NET Control to generate, create USPS Intelligent Mail image in .NET framework applications.
The WMI class Win32_Desktop contains settings by the users With the following command, you will get to know whether user FBI\ FoxMulder has activated a screensaver on computer AgentPC04:
Barcode Generator In VB.NET
Using Barcode creation for .NET framework Control to generate, create barcode image in .NET framework applications.
Get-WmiObject Win32_Desktop -computer AgentPC04 | where { $_Name -eq "DBI\FoxMulder" } | select screensaveractive
Create GS1-128 In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create EAN 128 image in ASP.NET applications.
17 DIRECTORY SERVICES
Code128 Generation In Visual C#.NET
Using Barcode generator for .NET framework Control to generate, create USS Code 128 image in VS .NET applications.
You can access Active Directory entries using the WMI classes in the WMI namespace root\directory\ldap For example, the following command lists all groups whose name starts with the letter M:
Scan Code-128 In VS .NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
Get-WmiObject -Class ds_group -Namespace root\directory\ldap "DS_name like m%'" -Filter
ECC200 Creation In Visual Basic .NET
Using Barcode generator for .NET Control to generate, create DataMatrix image in Visual Studio .NET applications.
SystemDirectoryServices and the ADSI Adapter
Reading UCC - 12 In .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
The classes of the NET namespace SystemDirectoryservices are an encapsulation of ADSI ADSI is a Component Object Model (COM) component introduced in the era of Windows 2000 Unfortunately, not all functions in the NET library are encapsulated, and therefore ADSI still plays a role in WPS
Drawing Code 39 In Java
Using Barcode maker for Java Control to generate, create USS Code 39 image in Java applications.
17 Directory Services
Data Matrix 2d Barcode Scanner In VS .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications.
NOTE The classes in the namespace SystemDirectoryServices work only when the ADSI COM component has been installed, too In the following text, the ADSI COM component is referred to as classic ADSI
The classes in the NET namespace SystemDirectoryservices offer only very general mechanisms for the access to directory services There are no longer speci c classes for single directory services as they exist in classic ADSI Certain operations (for example, changing the password in a user object) therefore must be called directly or indirectly via classic ADSI
Architecture
Figure 171 shows the architecture of ADSI under NET A NET program (managed code) has three options to access a directory service:
Use of objects in the namespace SystemDirectoryservices to execute directory service operations Use of objects in the namespace SystemDirectoryservices to call operations in classic ADSI Direct use of classic ADSI via COM interoperability
Integration with ADSI
That all calls in SystemDirectoryservices are executed in ADSI can be proved by error messages of the NET class library For example, the class DirectoryEntry delivers the following error message referring to the COM interface InteropIADS when calling CommitChanges(), if the object to be created already exists:
SystemRuntimeInteropServicesCOMException (0x80071392): The object already exists at SystemDirectoryservicesInteropIAdsSetInfo() at SystemDirectoryservicesDirectoryEntryCommitChanges()
SystemDirectoryServices and the ADSI Adapter
C/C++ Client
COM Client
Access via NativeObject
NET Client
SystemDirectoryServices SystemDirectoryServicesdll
Active Directory Service Interface (ADSI) activedsdll ADSI Provider LDAP:// adsldpdll LDAP-API wldap32dll ADSI Provider WinNT:// adsntdll
Win32-API
Network
17 DIRECTORY SERVICES
Exchange Server, Active Directory, ua
NT40 NT5x (without AD)
Figure 171 Programming interfaces for Active Directory This does not mean anything other than that the calling of
CommitChanges() in the class DirectoryEntry has internally been transferred to the method SetInfo() in the interface System DirectoryservicesInteropIADs SetInfo() is the well-known
method from classic ADSI used to return the property cache to the directory service and thus to make all changes persistent
WARNING The namespace SystemDirectoryservicesInterop is not documented and is displayed in the object browser of Visual Studio In this namespace, the interfaces IADs, IADsContainer, and so on (well known from classic ADSI) are de ned Because an instancing of interfaces is no longer possible in NET, the interfaces had to be combined with classes
17 Directory Services
Object Model
The classes in the namespace SystemDirectoryservices can be divided into two groups:
General classes for the access to leaves and containers Classes for the execution of LDAP search queries (see 19)
The two central classes in the namespace are DirectoryEntry and DirectoryEntries
Class DirectoryEntry
The class DirectoryEntry represents any directory entry regardless of whether it is a leaf or a container This class owns the property Children of the type DirectoryEntries This object volume is lled only when the object is a container (that is, if it has subobjects) The object volume also exists in a leaf object; however, it is empty In the attribute Property, the DirectoryEntry class has an object volume of the type PropertyCollection, which represents the volume of the directory attributes The PropertyCollection has three subordinated object volumes: