Logon Script

G

Guest

Guest
Archived from groups: microsoft.public.win2000.group_policy (More info?)

First of all Thanks for all the assistance with getting a good logon script
site.

Now my problem.

I want this script to disconnect the drive mapping if it is mapped to a
different share.

I.E. user has Y drive mapped to another computer.

This script is suppose to check the drive mapping and if it is in error
remap it to the correct drive.

Here is my script (I know I have a lot disabled this isnt my finished
working copy)

' Logon1.vbs
' VBScript logon script program.
'
' ----------------------------------------------------------------------
' Copyright (c) 2002 Richard L. Mueller
' Hilltop Lab web site - http://www.rlmueller.net
' Version 1.0 - November 10, 2002
' Version 1.1 - February 19, 2003 - Standardize Hungarian notation.
' Version 1.2 - June 10, 2003 - Map user home directory.
' Do not test computer group membership.
' Version 1.3 - January 25, 2004 - Modify error trapping.
'
' This program demonstrates how to bind to the user object, test for
' user group membership, map network shares according to user group
' membership, and connect shared printers. The IsMember function used
' keeps track of user group memberships in a dictionary object. Since
' the WinNT provider is used, the IsMember function reveals membership
' in the "Primary Group", but does not reveal "Nested Group"
' memberships. It cannot be used to test computer group membership. The
' NetBIOS domain name is hardcoded.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.

Option Explicit

Dim objGroupList, objUser, strGroup, objNetwork, strNTName
Dim strNetBIOSDomain, strHomeDrive, strHomeShare

' NetBIOS Domain name.
strNetBIOSDomain = "Griffin"

Set objNetwork = CreateObject("Wscript.Network")

' Loop required for Win9x clients during logon.
strNTName = ""
On Error Resume Next
Do While strNTName = ""
strNTName = objNetwork.userName
Err.Clear
If Wscript.Version > 5 Then
Wscript.Sleep 100
End If
Loop
On Error GoTo 0

' Bind to the user object in Active Directory with the WinNT provider.
Set objUser = GetObject("WinNT://" & strNetBIOSDomain & "/" _
& strNTName & ",user")

' Map user home directory.
'strHomeShare = objUser.homeDirectory
'If strHomeShare <> "" Then
' strHomeDrive = objUser.homeDirDrive
' If strHomeDrive = "" Then
' strHomeDrive = "H:"
' End If
' On Error Resume Next
' objNetwork.MapNetworkDrive strHomeDrive, strHomeShare
' If Err.Number <> 0 Then
' On Error GoTo 0
' objNetwork.RemoveNetworkDrive strHomeDrive, True, True
' objNetwork.MapNetworkDrive strHomeDrive, strHomeShare
' End If
' On Error GoTo 0
'End If

' Map a drive if the user is a member of the group.
strGroup = "04 Corporate"
If IsMember(strGroup) Then
On Error Resume Next
objNetwork.MapNetworkDrive "Y:", "\\data\f"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "Y:", True, True
objNetwork.MapNetworkDrive "Y:", "\\data\f"
End If
On Error GoTo 0
End If

' Add the shared printer connection.
''objNetwork.AddPrinterConnection "LPT1:", "\\PrintServer\Printer1"

' Clean up.
Set objGroupList = Nothing
Set objUser = Nothing
Set objNetwork = Nothing

Function IsMember(strGroup)
' Function to test for user group membership.
' strGroup is the NT name (sAMAccountName) of the group to test.
' objGroupList is a dictionary object, with global scope.
' Returns True if the user is a member of the group.

If IsEmpty(objGroupList) Then
Call LoadGroups
End If
IsMember = objGroupList.Exists(strGroup)
End Function

Sub LoadGroups
' Subroutine to populate dictionary object with group memberships.
' objUser is the user object, with global scope.
' objGroupList is a dictionary object, with global scope.

Dim objGroup
Set objGroupList = CreateObject("Scripting.Dictionary")
objGroupList.CompareMode = vbTextCompare
For Each objGroup In objUser.Groups
objGroupList(objGroup.name) = True
Next
Set objGroup = Nothing
End Sub


Thanks for all the help in this matter in advance.
 
G

Guest

Guest
Archived from groups: microsoft.public.win2000.group_policy (More info?)

Just wanted to make this easier to read.

' This program demonstrates how to bind to the user object, test for
' user group membership, map network shares according to user group
' membership. The IsMember function used
' keeps track of user group memberships in a dictionary object. Since
' the WinNT provider is used, the IsMember function reveals membership
' in the "Primary Group", but does not reveal "Nested Group"
' memberships. It cannot be used to test computer group membership. The
' NetBIOS domain name is hardcoded.


Option Explicit

Dim objGroupList, objUser, strGroup, objNetwork, strNTName
Dim strNetBIOSDomain

' NetBIOS Domain name.
strNetBIOSDomain = "Griffin"

Set objNetwork = CreateObject("Wscript.Network")

' Loop required for Win9x clients during logon.
strNTName = ""
On Error Resume Next
Do While strNTName = ""
strNTName = objNetwork.userName
Err.Clear
If Wscript.Version > 5 Then
Wscript.Sleep 100
End If
Loop
On Error GoTo 0

' Bind to the user object in Active Directory with the WinNT provider.
Set objUser = GetObject("WinNT://" & strNetBIOSDomain & "/" _
& strNTName & ",user")


' Map a drive if the user is a member of the group.
strGroup = "04 Corporate"
If IsMember(strGroup) Then
On Error Resume Next
objNetwork.MapNetworkDrive "Y:", "\\data\f"
If Err.Number <> 0 Then
On Error GoTo 0
objNetwork.RemoveNetworkDrive "Y:", True, True
objNetwork.MapNetworkDrive "Y:", "\\data\f"
End If
On Error GoTo 0
End If


' Clean up.
Set objGroupList = Nothing
Set objUser = Nothing
Set objNetwork = Nothing

Function IsMember(strGroup)
' Function to test for user group membership.
' strGroup is the NT name (sAMAccountName) of the group to test.
' objGroupList is a dictionary object, with global scope.
' Returns True if the user is a member of the group.

If IsEmpty(objGroupList) Then
Call LoadGroups
End If
IsMember = objGroupList.Exists(strGroup)
End Function

Sub LoadGroups
' Subroutine to populate dictionary object with group memberships.
' objUser is the user object, with global scope.
' objGroupList is a dictionary object, with global scope.

Dim objGroup
Set objGroupList = CreateObject("Scripting.Dictionary")
objGroupList.CompareMode = vbTextCompare
For Each objGroup In objUser.Groups
objGroupList(objGroup.name) = True
Next
Set objGroup = Nothing
End Sub


I have tried to move the objNetwork.Remove command to the beginning and it
will not remove the mapping of the Y drive. as seen below

strGroup = "04 Corporate"
If IsMember(strGroup) Then
On Error Resume Next
objNetwork.RemoveNetworkDrive "Y:", True, True (Added)
objNetwork.MapNetworkDrive "Y:", "\\data\f"

As I posted above I am trying to create a logon script that will remove a
mapped drive letter and replace it with the one in the script for various
user groups.

Last of all Thanks for any assistance in this matter.


Thanks