Previous Page
Next Page

Adding a Group to a Logon Script Step-by-Step Exercises

In this section, you will add a group to a logon script. To perform this exercise, you will need the following (you can modify the following exercise to match your existing test network as appropriate):

  • Groups: hrGroup, MarketingGroup, ProductionGroup and SalesGroup

  • A file server called London

  • A User share called London\home

  • Departmental shares called hr, sales, marketing, and production

  • Printer shares called hrPrinter, marketingPrinter, productionPrinter, and salesPrinter

  • An assortment of users who are members of the previously mentioned groups to test with

  • A remote workstation that is a member of the NWTraders domain

1.
Open Notepad or the script editor of your choice.

2.
Open \My Documents\Microsoft Press\VBScriptSBS\ch16\StepByStep\AddGroupToLogonScriptStarter.vbs and save it as YourNameAddGroupToLogonScript.vbs.

3.
Look over the script and add comments to each declared variable.

4.
With the constants, declare a new constant called Production. Set it equal to cn=productiongroup. The completed constant section will look like the following:

Const HR = "cn=hrgroup"
Const MARKETING = "cn=marketinggroup"
Const SALES = "cn=salesgroup"
Const PRODUCTION = "cn=productiongroup"

5.
Add a new case d to the Select Case statement. This new case is equal to finding the value assigned to the constant Production in the string assigned to strGroups. If the case is met, the script should jump to a subroutine called ProductionSub. The new Select Case statement looks like the following:

Select Case GroupMember
  Case a = InStr(strGroups, HR)
    HRsub
  Case b = InStr(strGroups, SALES)
    SalesSub
  Case c = InStr(strGroups, MARKETING)
    MarketingSub
  Case d = InStr (strGroups, PRODUCTION)
    ProductionSub
End Select

6.
At the bottom of the various subroutines, add a new subroutine called ProductionSub. End the subroutine with the End Sub command. It will look like the following:

Sub ProductionSub

End Sub

7.
For the first line of the ProductionSub subroutine, use WScript.Echo to inform the user that she is in the Production subroutine. Your line of text could look like the following:

WScript.Echo("made it to production")

8.
Use the MapNetworkDrive method of the WshNetwork object to map the drive letter "P:" to the production share on the London server. This line of code will look like the following:

wshNet.MapNetworkDrive "P:","\\london\Production\"

9.
Use the AddWindowsPrinterConnection method of WshNetwork to add a connection to the production printer that is set up on the London server. This line of code will look like the following:

wshNet.AddWindowsPrinterConnection "\\london\ProductionPrinter"

10.
Set the new production printer to be the default printer for members of the production group. To do this, use the SetDefaultPrinter command of the WshNetwork object. This line of code will look like the following:

wshNet.SetDefaultPrinter "\\london\ProductionPrinter"

11.
Save and test the script by logging into the domain as one of your test users from a remote machine. If there are problems with the script, compare it with \My Documents\Microsoft Press\VBScriptSBS\ch16\AddGroupToLogonScript.vbs.


Previous Page
Next Page