![]() |
|
|
| Become a Columnist Microsoft Exchange Site Microsoft Support SiteMSDN Exchange Site | ||
|
|
Building Com objects in VBS for NT and ExchangeThe following article is a side article to my Web GALMOD com article to demonstrate an easy way to build the Com objects necessary for this article and show how you can use them for other apps. (Note this article refers to using Com+ apps on Windows 2000) Updated 2/2004 to include information about changes to default Com+ Security in Windows 2003 I guess the first question is why use Com+ objects ? Well in my Web GALMOD article I needed a way for a user to be able to modify the properties of an Active directory account via a web page and I didn't want to have to delegate any rights to the user themselves. So one of the good features of Com objects is that you can configure them to run under a different account context, so when a function is executed from a web page this function will be executed on the server under the context of the user the Com app is setup under The next question is why use VBS well for development purposes its great it gets around the need to recompile your object in VB and C++ every time you make a change. With VBS once you have registered the object you can then go it and just modify the VBS script and your changes are instant. Once you have the code in your app finialized to get the best performance I recommend you recompile your code as a VB active X dll. Getting the Software to build the objectThere is only one piece of software you need to start building Com objects in VBS and this is the Windows Script Component Wizard which you can download from here. The MSDN doco is really good for this stuff so I'm only going to touch on the stuff you need to know to make the Com object for the Galmod article. If you want to have a look at the MSDN doco have a look here. Building the GALMOD Com objectThe first thing to do is start up the script component wizard and you should be presented with a screen asking for Name and filename details. To match the names I have put in the samples that are downloadable from my other article use the following Names. Name: Galmod On the special characteristics page make sure you have VBscript selected as the language and select the radio button Support Active Server pages Leave component properties blank In Component methods this is the place where the two functions that the GALMOD app preforms are defined. The first method is called showgal and this function has one parameter which is the calling users UserID (Ive called it CUSERID). The next function is the updateuser function that is used to update the user in Active directory. This function has several Parameters which are detailed below.
DN = DN name of AD object Leave Events blank and that's it your finished. You should now have a new file in the location you specified on the first screen called galmod.wsc if you open this up with a text editor you will see that you have a template for a Com+ object with two blank functions. Now all you have to do is put the code in for the functions that are defined in the Com object for the code used in the GALMOD com object please see the download on my other article (Rember you need to change the domain name variable in this code to match your own) Once you have filled in all the functions in the object file you should move this file to the location where you wish to have it stored on your server eg winnt\system32 (or wherever you want to keep your custom objects). Registering your new ObjectTo register your new object simply right click the object in explorer and select Register from the context menu (its that easy) Creating a COM+ Wrapper for your objectOnce you've built and registered your object you now need to create a COM+ wrapper so you can set the user context you wish it to run under. To do this you need to go into Component Services under Administration Tools and create a new Empty Com+ app (and call it for instance GalUpdateApp) This will start the Com+ application creation wizard, In the Identity screen you should select "This User" to specify a user to run the Com+ app under see below for details on thisSpecify a user for the GALMOD Com+ objectWith the GALMOD Com object for it to work correctly you must have it running under an account that has rights to modify the active directory phone number properties for all users in your domain. There are a few ways to do this, the easiest way is to set it to a user that has administrative rights in your domain (this is the least secure way however and has the potential to be possibly exploited in a negative way). The most secure way is to create an account for the Com object to run under then using the Active Directory delegation wizard assign this accounts rights to modify Active Directory properties that you wish the account to modify.Changes to the default Security under Windows 2003In Windows 2003 the default setting for security has changed compared to that of Windows 2000. Windows 2003 now enforces security checks for COM+ applications which means if you don't change the setting from the default and you don't configure the security roles in your application you may see the following error message when you try and use your COM+ object in a ASP page (this is if you have turned off show friendly Http errors). To solve this problem you can do one of two things the first thing you could do is configure the security roles in your COM+ application and give rights to all the accounts you want to run the application rights to the COM+ object. The other option (which is the easy one) is to disable access checks for this COM+ app, to do this from the properties of the COM+ wrapper on the security tab in the authorization section remove the tick from "Enforce Access Check for this application". Import the Galmod Com+ application object into the WrapperOnce you have created your Com+ wrapper you now need to import the Component that you have registered into this wrapper so it will now run under the user context of this application wrapper. To do this open the Com+ app you have created above in Component Services and then open the components folder and then right click on this folder and select new component from the context menu. This will start the new component wizard, you then need to select import components that are already registered and then select the galmod.wsc component from the list that is presented. Thats pretty much it now your ready to use your object in an Active Server page or some other application. To use this new object in Active server pages you simply call the Server.Creatobject in some server side script and then use any of the methods defined in your Com object. eg <%@ Language=VBScript %>
|
Disclaimer: Your use of the information contained in these pages is at your sole risk. All information on these pages is provided "as is", without any warranty, whether express or implied, of its accuracy, completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by Stephen Bryant or Pro Exchange. OutlookExchange.Com, Stephen Bryant and Pro Exchange shall not be liable for any damages you may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.
Copyright Stephen Bryant 2008