![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
![]()
In this topic I would like to explain briefly the framework in which we develop our scripts for manipulating directories.
Due to the fact that Visual Basic Script is an easy to learn variant of scripting which offers almost all imaginable possibilities for accessing a directory service, we will concentrate on this scripting language in the SelfADSI project.
The following contents are available here:
|
WScript.Echo "Hello World" |
Call by cscript hello.vbs:
Call by wscript hello.vbs:
By the way, the call parameter of the two utilities cscript and wscript are identical:
MSDN info
about the commandline parameter for cscript and wscript
In most cases cscript is used. Thus, each output is simply shown in a new line of the terminal window, whereas wscript opens a new message popup window for every line of output! Furthermore, with cscript you can send the script output to a text file by using pipelining.
After all you can configure your windows shell to run VBS files in a command window directly, so that this call
C:>cscript [//WSH parameters] <path to the script file > [script parameters]
is NOT neccesary any more. Instead, it would be great if we could just start the script like a normal program by entering the script name on the command line and hitting enter. This can be done by changing the appropriate registry key:
HKEY_CLASSES_ROOT\
VBSFile\
Shell\
Open\
Command\
(Standard) REG_EXPAND_SZ:
cScript.exe //nologo "%1" %*
After that registry change you can start the 'Hello World' script as follows:
You can find a registry import file for automating the the neccessary changes here:
| Download vbsfile.reg |
You can debug Visual Basic Scripts step by step with the Microsoft Script Debugger.
Download Website for the Microsoft Script Debugger
Originally the debugger was made to debug scripts which are embedded in HTML. To run a Visual Basic Script directlry in the Debugger you have to insert the command "stop" into you code. When you call the script with the parameter //x, then the debugger pops up just on that line where you inserted the stop command:
C:>cscript //x test.vbs
But the Microsoft script debugger does not have very comfortable debugger functions like the evaluation of variable values. And you cannot edit the script source code directly in the debugger window. Therefore I would recommend a specialized script editor for this task, for example VBSEdit:
Maybe you want to give your script to other people but you dont want to let them know the source code of this script? There is a very simple (but quite low-level and weak) encryption possibilty with the Microsoft Script Encoder. You can encrypt complete scripts on the command line - the encrypted script can be still run on all computers where the original script could have be run also.
Download website for the Mcrosoft Script Encoder
Currently the ADSI interface is availble in version 2.5. This version offers the access not only to native LDAP directories like ADS. You can also access other (old-fashioned) directory services with the so-called providers. There are ADSI-Providers for NT 4.0, Novell NetWare 3.x, Netware Directory Service and also for the Metabase of the Microsoft Internet Information Service.
If you want to find out what ADSI version is installed on your computer, you have to look in the registry. There the version is stored in the following key:
HKEY_CLASSES_ROOT\
SOFTWARE\
Microsoft\
Active Setup \
Installed Components\
{E92B03AB-B707-11d2-9CBD-0000F87A369E}
Version REG_SZ
Oddly enough - the version listed in this key is in modern Windows operating systems "5,0,00,0". Nevertheless in this case the version is 2.5. There is a detailed description how to find out the ADSI-Version by means of evaluating the file versions of the according DLL files on the Microsoft website: Knowledge Base Article Q216290.
For these operating systems the libraries of the ADSI interface are included by default. So you dont have to prepare anything if you want to run a script which creates and uses ADSI objects and which access a directory service in this way. To detect the version of ADSI your computer runs with you can follow the instructions outlined above in the last paragraph.
For these operating systems the ADSI interface is not included by default. A Script using ADSI obejcts and functions would raise a runtime error similar to this:
If you want to use ADSI under Windows 9x or Windows NT, you need the so called Active Directory Extensions for Windows NT 4.0. This is a free driver which is used to adds DFS and printers search capabilities to NT and W9x clients. And one of the advantages of these additional features is the implementation of the ADSI interface. This driver is also known as "DSClient". The setup requires a rebott on the computers.
Download website Seite
für die ADS Extensions for W9x und NT