Behind the Scenes of the Enterprise Management Example

By now you have played with this example to see what it can do. It is time now to see what happens under the hood. It is quite simple and straightforward, if you look at a few things at a time.

If you use the Project-References menu of Visual Basic, you will notice that we have selected four Bindview DirectScript type libraries. Their names all start with "Bindview DirectScript ...".

You can see some global properties of the project using Project-Network Management Properties. You will notice that the Startup Object is frmMain.

The application contains a single Form: frmMain. This form has a number of controls. There are buttons, some dropdown combo boxes and a tabsheet with five property sheets. Click on some of these to see their design time properties.

Double click on the form and go to the General-Declarations section. You will see:

Option Explicit
Dim NSpaceContainer As IADsContainer 'will be instantiated in Form_Load
Dim Security As IObjectSecurity

We hope you always say Option Explicit in all your projects. It does some reasonable amount of compile time checking for you.

We have two global objects. NSapceContainer is of type IADsContainer. It will allow us to enumerate all Domains in our network. Security represents the ObjectSecurity object. This object has nothing to do with ADSI. We have included it with DirectScript because we thought you can put it to good use when controlling access permissions over files and directories and registry entries and printers. So far we have only declared these objects. They have not yet been instantiated.

One word of caution: this is not a robust, professional quality application. Its aim is to explain how to gainfully employ DirectScript objects. It is not completely error free. Once in a while we have included "On error goto" statements to show you how you can recover from errors, but total robustness will need more effort.

The actual instantiation happens in the Form_Load event. If you locate this event in your code, you will see:

Set NSpaceContainer = GetObject("NTDS:") 'You are now connected to DirectScript
Set Security = CreateObject("DirectScript.ObjectSecurity")

cmdCreateGroupInDomain.Enabled = False 'Disallow this till a domain is selected

cmdCreateUserInDomain.Enabled = False 'Disallow this till a domain is selected

cmdDeleteGroup.Enabled = False  'Disallow till a group is selected

The statement Set NSpaceContainer = GetObject("NTDS:") creates a NameSpace object and gets its IADsContainer interface. The statement Set Security = CreateObject("DirectScript.ObjectSecurity") does the same thing for Security. Once these objects have been created, they are available for the rest of the code. Some buttons are also disabled till they can be safely enabled later.

The next section shows you code fragments within this example.


See also