While using a batch file to perform logon scripts is the easiest way to map drives and call executables, I prefer using VBScripts because it provides the capability of using group membership to determine who the logon script function is supposed to work for.
Determining group membership can be done during Group Policy processing, but we found using Group Policies to determine membership added to logon times. This is especially the case if multiple policies have to determine group membership.
Map a Drive Letter to a Network Drive based on Group Membership
The script below will query Active Directory for group membership to determine what drive mappings the user is to get.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set wshNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
If IsArray(CurrentUser.MemberOf) Then
strGroups = LCase(Join(CurrentUser.MemberOf))
strGroups = lcase(CurrentUser.MemberOf)
Const GroupName_GROUP = "cn=name of group in Active Directory"
If InStr(strGroups, GroupName_GROUP) Then
' Removes Mapped Network Drive in the event a drive was previously mapped
If objFSO.DriveExists("G:") Then
wshNetwork.RemoveNetworkDrive "G:", True, True
' Maps G: Drive to Windows Share
wshNetwork.MapNetworkDrive "G:", "\\Server\Share"
Calling an Executable File from the Logon Script
Sometimes it is necessary for a logon script to call upon an executable to complete a certain task at logon. We use this the below commands to call an executable on a Windows Share that will audit our PCs.
This script functions the same as the “Start \\Server\Share\audit32.exe” command that can be used in a Batch File, but we chose to go with the VBScript route so we can combine our Logon Scripts under one file in hopes to boost logon speeds.
Set WshShell = WScript.CreateObject("WScript.Shell")