"Microsoft Newsgroups" <james.mcgril@xxxxxx> wrote in message
news:OktkLWiEKHA.5780@xxxxxx
>I am new to scripting with vb and want to create a script that will
>automatically may some network drives for our end users (they will be
>logged into their machine under their profile). Does anyone have any
>samples I could use. It would be greatly apprectiated.
>
> James In VBScript use the wshNetwork object to map a drive to a share. For
example, to map a share to drive K:
=========
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare"
=====
To map a shared printer (and make it the default):
==========
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.AddWindowsPrinterConnection "\\MyServer\MyPrinter"
objNetwork.SetDefaultPrinter "\\MyServer\MyPrinter"
=========
The simplest way to map drives according to group membership (assuming you
only have a few groups to check and are only concerned with direct group
membership) is to use the IsMember method of the group object. For example:
=========
Set objNetwork = CreateObject("Wscript.Network")
' Bind to current user object.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
' Bind to group, using full Distinguished Name.
Set objGroup = GetObject("LDAP://cn=Test Group,ou=West,dc=MyDomain,dc=com")
' Check group membership.
If (objGroup.IsMember(objUser.AdsPath) = True) Then
' User is a member of the group, so map a drive.
objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare"
End If
======
For more examples logon scripts that handle group nesting, see this link:
http://www.rlmueller.net/freecode2.htm
Also, a discussion of the pitfalls involved in methods many people use to
check group membership:
http://www.rlmueller.net/MemberOf.htm
Plus, an FAQ on configuring logon scripts:
http://www.rlmueller.net/LogonScriptFAQ.htm
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--