Computer Performance, Windows 2003, Exchange 2003, Logon Scripts

 

VBScript - WScript.Echo pop-up messages

Introduction to Echo confirmation message

The purpose of the WSH pop-up message is to let you know that the script has completed successfully.  It can also give you valuable extra information, for instance, the number of objects created, and the container where they are 'born'.

Example script to test WScript.echo

If we use the script below as our 'vehicle' then we can experiment with WScript.Echo messages to confirm that the script worked properly.

What the script does is to create ten users in an OU called BulkGuy.  It should work in any domain.  If you do not have a domain available then adapt the WSCript.echo method to a simpler script.

' VBScript to create an OU called BulkGuy
' VBScript then creates 10 Users in OU BulkGuy
' Guy Thomas - January 2004

Dim objRoot, objDomain, objOU, objContainer
Dim strName
Dim intUser

strName ="BulkGuy"

Set objRoot = GetObject("LDAP://rootDSE")
Set objDomain = GetObject("LDAP://" & objRoot.Get("defaultNamingContext"))

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objOU=objDomain.Create("organizationalUnit", "ou=BulkGuy")
objOU.Put "Description", "Guy's Bulk Users OU"
objOU.SetInfo

Set objContainer = GetObject("LDAP://OU=BulkGuy," & _
objRootDSE.Get("defaultNamingContext"))

For account = 1 To 10
Set objLeaf = objContainer.Create("User", "cn=" & strName & account)
objLeaf.Put "sAMAccountName", strName & account
objLeaf.SetInfo
intUser = intUser +1
Next

WScript.Echo "10  Users created BulkGuy"
WScript.quit

Using the WScript.Echo method to pop-up a message.

' Plain String message
WScript.Echo "10  Users created BulkGuy"

 

Note 1: It is the command .Echo that WScript actually uses to produces a message box. WScript.quit has a very different meaning.

Improvement: Introducing the variable intUser into the .Echo method.

 


Variable intUser added for extra information
WScript.Echo intUser & "  10  Users created BulkGuy"

 

Note 1:  The key is to have the intUser variable  inside the For....Next loop

Note 2:  To join the variable with the string use ampersand (&) not plus.  This method is called concatenation.

Note 3:  The space between the speech marks and the 10 is trivial item, but it improves readability.


See Also

 .


Google

Webcomputerperformance.co.uk

GFi Events Manager

Guy Recommends: GFi EventsManager

Let GFI EventsManager do the dirty work! Have event logs monitored automatically and get warned about critical events! Download a copy here

 

Home Copyright © 1999-2009 Computer Performance LTD All rights reserved

Please report a broken link, or an error.