Windows Vista Forums

Map Network Drive
  1. #1


    Microsoft Newsgroups Guest

    Map Network Drive

    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



      My System SpecsSystem Spec

  2. #2


    Pegasus [MVP] Guest

    Re: Map Network Drive


    "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
    Have a look at the thread "logon vbscript mapping drives", posted in this
    very newsgroup 9 days ago.



      My System SpecsSystem Spec

  3. #3


    Richard Mueller [MVP] Guest

    Re: Map Network Drive


    "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
    --



      My System SpecsSystem Spec

  4. #4


    Microsoft Newsgroups Guest

    Re: Map Network Drive

    That is exactly what I needed. Thanks Richard!

    James

    "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    message news:eD3k0prEKHA.1252@xxxxxx

    >
    > "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
    > --
    >
    >


      My System SpecsSystem Spec

  5. #5


    Microsoft Newsgroups Guest

    Re: Map Network Drive

    Richard,

    Mapping the printers is working great and so is mapping a generic network
    drive. But I have a couple more questions...

    1. I tried the following code to map a drive directly to a users directory.
    The user directory name matches the user name, so I thought I could modify
    the code you sent. But I get an error that the path could not be found.
    How can I fix that?

    Set objNetwork = CreateObject("Wscript.Network")
    Set objSysInfo = CreateObject("ADSystemInfo")
    strUserDN = objSysInfo.UserName
    Set objUser = GetObject("LDAP://" & strUserDN)
    objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strUserDN

    2. Will the mapped drives reconnect after the pc is restarted and the user
    logs in again?

    Any more help you could provide would be great!

    Regards,

    James



    "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    news:%23snFdrDFKHA.3964@xxxxxx

    > That is exactly what I needed. Thanks Richard!
    >
    > James
    >
    > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    > message news:eD3k0prEKHA.1252@xxxxxx

    >>
    >> "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
    >> --
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  6. #6


    Richard Mueller [MVP] Guest

    Re: Map Network Drive

    The value of strUserDN (objSysInfo.UserName) is the Distinguished Name of
    the user, not the "pre-Windows 2000 logon name" you need. You can retrieve
    the correct user name from the wshNetwork object. For example:
    ==========
    Set objNetwork = CreateObject("Wscript.Network")
    strName = objNetwork.UserName
    objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strName
    ==========
    A given user's Distinguished Name might be similar to:

    cn=Jim K. Smith,ou=Sales,ou=West,dc=MyDomain,dc=com

    while the same user's "pre-Windows 2000 logon" name might be:

    jsmith

    The Distinguished Name uniquely identifies the object and indicates where in
    Active Directory the object resides. The value "Jim K. Smith" is the "Common
    Name" of the user, and does not uniquely identify the user. The Common Name
    must be unique in the Container/OU (ou=Sales in my example), but there can
    be several users with the same Common Name. The "pre-Windows 2000 logon
    name" must be unique in the domain. This is also the value of the
    environment variable "username".
    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --

    "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    news:%230%23O3LEFKHA.1380@xxxxxx

    > Richard,
    >
    > Mapping the printers is working great and so is mapping a generic network
    > drive. But I have a couple more questions...
    >
    > 1. I tried the following code to map a drive directly to a users
    > directory. The user directory name matches the user name, so I thought I
    > could modify the code you sent. But I get an error that the path could
    > not be found. How can I fix that?
    >
    > Set objNetwork = CreateObject("Wscript.Network")
    > Set objSysInfo = CreateObject("ADSystemInfo")
    > strUserDN = objSysInfo.UserName
    > Set objUser = GetObject("LDAP://" & strUserDN)
    > objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strUserDN
    >
    > 2. Will the mapped drives reconnect after the pc is restarted and the
    > user logs in again?
    >
    > Any more help you could provide would be great!
    >
    > Regards,
    >
    > James
    >
    >
    >
    > "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    > news:%23snFdrDFKHA.3964@xxxxxx

    >> That is exactly what I needed. Thanks Richard!
    >>
    >> James
    >>
    >> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    >> message news:eD3k0prEKHA.1252@xxxxxx

    >>>
    >>> "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
    >>> --
    >>>
    >>>
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  7. #7


    James Guest

    Re: Map Network Drive

    Again, you have been a great help! I truly appreicate it. You have just
    helped make my job a lot easier. All I have to do to my script now is to
    add some code to check to see if the printers and drives are already mapped
    otherwise it will bomb out.

    James

    "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    message news:%23buPynEFKHA.4316@xxxxxx

    > The value of strUserDN (objSysInfo.UserName) is the Distinguished Name of
    > the user, not the "pre-Windows 2000 logon name" you need. You can retrieve
    > the correct user name from the wshNetwork object. For example:
    > ==========
    > Set objNetwork = CreateObject("Wscript.Network")
    > strName = objNetwork.UserName
    > objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strName
    > ==========
    > A given user's Distinguished Name might be similar to:
    >
    > cn=Jim K. Smith,ou=Sales,ou=West,dc=MyDomain,dc=com
    >
    > while the same user's "pre-Windows 2000 logon" name might be:
    >
    > jsmith
    >
    > The Distinguished Name uniquely identifies the object and indicates where
    > in Active Directory the object resides. The value "Jim K. Smith" is the
    > "Common Name" of the user, and does not uniquely identify the user. The
    > Common Name must be unique in the Container/OU (ou=Sales in my example),
    > but there can be several users with the same Common Name. The "pre-Windows
    > 2000 logon name" must be unique in the domain. This is also the value of
    > the environment variable "username".
    > --
    > Richard Mueller
    > MVP Directory Services
    > Hilltop Lab - http://www.rlmueller.net
    > --
    >
    > "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    > news:%230%23O3LEFKHA.1380@xxxxxx

    >> Richard,
    >>
    >> Mapping the printers is working great and so is mapping a generic network
    >> drive. But I have a couple more questions...
    >>
    >> 1. I tried the following code to map a drive directly to a users
    >> directory. The user directory name matches the user name, so I thought I
    >> could modify the code you sent. But I get an error that the path could
    >> not be found. How can I fix that?
    >>
    >> Set objNetwork = CreateObject("Wscript.Network")
    >> Set objSysInfo = CreateObject("ADSystemInfo")
    >> strUserDN = objSysInfo.UserName
    >> Set objUser = GetObject("LDAP://" & strUserDN)
    >> objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strUserDN
    >>
    >> 2. Will the mapped drives reconnect after the pc is restarted and the
    >> user logs in again?
    >>
    >> Any more help you could provide would be great!
    >>
    >> Regards,
    >>
    >> James
    >>
    >>
    >>
    >> "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    >> news:%23snFdrDFKHA.3964@xxxxxx

    >>> That is exactly what I needed. Thanks Richard!
    >>>
    >>> James
    >>>
    >>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    >>> message news:eD3k0prEKHA.1252@xxxxxx
    >>>>
    >>>> "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
    >>>> --
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  8. #8


    James Guest

    Re: Map Network Drive

    What is the switch or argument to make the mapped drive persistant?

    James

    "James" <donotreply@xxxxxx> wrote in message
    news:O6WCaBFFKHA.4316@xxxxxx

    > Again, you have been a great help! I truly appreicate it. You have just
    > helped make my job a lot easier. All I have to do to my script now is to
    > add some code to check to see if the printers and drives are already
    > mapped otherwise it will bomb out.
    >
    > James
    >
    > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    > message news:%23buPynEFKHA.4316@xxxxxx

    >> The value of strUserDN (objSysInfo.UserName) is the Distinguished Name of
    >> the user, not the "pre-Windows 2000 logon name" you need. You can
    >> retrieve the correct user name from the wshNetwork object. For example:
    >> ==========
    >> Set objNetwork = CreateObject("Wscript.Network")
    >> strName = objNetwork.UserName
    >> objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strName
    >> ==========
    >> A given user's Distinguished Name might be similar to:
    >>
    >> cn=Jim K. Smith,ou=Sales,ou=West,dc=MyDomain,dc=com
    >>
    >> while the same user's "pre-Windows 2000 logon" name might be:
    >>
    >> jsmith
    >>
    >> The Distinguished Name uniquely identifies the object and indicates where
    >> in Active Directory the object resides. The value "Jim K. Smith" is the
    >> "Common Name" of the user, and does not uniquely identify the user. The
    >> Common Name must be unique in the Container/OU (ou=Sales in my example),
    >> but there can be several users with the same Common Name. The
    >> "pre-Windows 2000 logon name" must be unique in the domain. This is also
    >> the value of the environment variable "username".
    >> --
    >> Richard Mueller
    >> MVP Directory Services
    >> Hilltop Lab - http://www.rlmueller.net
    >> --
    >>
    >> "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    >> news:%230%23O3LEFKHA.1380@xxxxxx

    >>> Richard,
    >>>
    >>> Mapping the printers is working great and so is mapping a generic
    >>> network drive. But I have a couple more questions...
    >>>
    >>> 1. I tried the following code to map a drive directly to a users
    >>> directory. The user directory name matches the user name, so I thought I
    >>> could modify the code you sent. But I get an error that the path could
    >>> not be found. How can I fix that?
    >>>
    >>> Set objNetwork = CreateObject("Wscript.Network")
    >>> Set objSysInfo = CreateObject("ADSystemInfo")
    >>> strUserDN = objSysInfo.UserName
    >>> Set objUser = GetObject("LDAP://" & strUserDN)
    >>> objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strUserDN
    >>>
    >>> 2. Will the mapped drives reconnect after the pc is restarted and the
    >>> user logs in again?
    >>>
    >>> Any more help you could provide would be great!
    >>>
    >>> Regards,
    >>>
    >>> James
    >>>
    >>>
    >>>
    >>> "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    >>> news:%23snFdrDFKHA.3964@xxxxxx
    >>>> That is exactly what I needed. Thanks Richard!
    >>>>
    >>>> James
    >>>>
    >>>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote
    >>>> in message news:eD3k0prEKHA.1252@xxxxxx
    >>>>>
    >>>>> "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
    >>>>> --
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >


      My System SpecsSystem Spec

  9. #9


    Richard Mueller [MVP] Guest

    Re: Map Network Drive

    objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare", True

    The third parameter given to the MapNetworkDrive method, which is optional,
    indicates if the mapping is persistent. The default is False. Because the
    user can map drives to the standard letters used in the logon script and
    make them persistent, I generally account for this. The command will raise
    an error if there is a persistent drive mapping. I use code similar to below
    to account for this:
    =========
    ' Trap possible error because K: has a persistent mapping.
    On Error Resume Next
    objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare"
    If (Err.Number <> 0) Then
    ' Mapping raised error, remove existing mapping.
    ' Restore normal error handing so we are alerted to errors.
    On Error GoTo 0
    objNetwork.RemoveNetworkDrive "K:", True, True
    ' Try again. If there is an error this time, we are alerted.
    objNetwork.MapNetworkDrive "K:", "\\MyServer\MyShare"
    End If
    ' Restore normal error handling.
    On Error GoTo 0
    ==========
    The RemoveNetworkDrive method has one required parameter, the drive letter,
    and two optional. The first optional parameter indicates if the mapping is
    to be removed even if it is use. The second optional parameter indicates if
    removal is persistent, so the mapping is no longer persistent. I hope this
    helps. You can check WSH documentation for details of the MapNetworkDrive
    and RemoveNetworkDrive methods. See this link to download the documentation:

    http://www.microsoft.com/downloads/d...displaylang=en

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --

    "James" <donotreply@xxxxxx> wrote in message
    news:%23LxdOdFFKHA.2376@xxxxxx

    > What is the switch or argument to make the mapped drive persistant?
    >
    > James
    >
    > "James" <donotreply@xxxxxx> wrote in message
    > news:O6WCaBFFKHA.4316@xxxxxx

    >> Again, you have been a great help! I truly appreicate it. You have just
    >> helped make my job a lot easier. All I have to do to my script now is to
    >> add some code to check to see if the printers and drives are already
    >> mapped otherwise it will bomb out.
    >>
    >> James
    >>
    >> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
    >> message news:%23buPynEFKHA.4316@xxxxxx

    >>> The value of strUserDN (objSysInfo.UserName) is the Distinguished Name
    >>> of the user, not the "pre-Windows 2000 logon name" you need. You can
    >>> retrieve the correct user name from the wshNetwork object. For example:
    >>> ==========
    >>> Set objNetwork = CreateObject("Wscript.Network")
    >>> strName = objNetwork.UserName
    >>> objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strName
    >>> ==========
    >>> A given user's Distinguished Name might be similar to:
    >>>
    >>> cn=Jim K. Smith,ou=Sales,ou=West,dc=MyDomain,dc=com
    >>>
    >>> while the same user's "pre-Windows 2000 logon" name might be:
    >>>
    >>> jsmith
    >>>
    >>> The Distinguished Name uniquely identifies the object and indicates
    >>> where in Active Directory the object resides. The value "Jim K. Smith"
    >>> is the "Common Name" of the user, and does not uniquely identify the
    >>> user. The Common Name must be unique in the Container/OU (ou=Sales in my
    >>> example), but there can be several users with the same Common Name. The
    >>> "pre-Windows 2000 logon name" must be unique in the domain. This is also
    >>> the value of the environment variable "username".
    >>> --
    >>> Richard Mueller
    >>> MVP Directory Services
    >>> Hilltop Lab - http://www.rlmueller.net
    >>> --
    >>>
    >>> "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    >>> news:%230%23O3LEFKHA.1380@xxxxxx
    >>>> Richard,
    >>>>
    >>>> Mapping the printers is working great and so is mapping a generic
    >>>> network drive. But I have a couple more questions...
    >>>>
    >>>> 1. I tried the following code to map a drive directly to a users
    >>>> directory. The user directory name matches the user name, so I thought
    >>>> I could modify the code you sent. But I get an error that the path
    >>>> could not be found. How can I fix that?
    >>>>
    >>>> Set objNetwork = CreateObject("Wscript.Network")
    >>>> Set objSysInfo = CreateObject("ADSystemInfo")
    >>>> strUserDN = objSysInfo.UserName
    >>>> Set objUser = GetObject("LDAP://" & strUserDN)
    >>>> objNetwork.MapNetworkDrive "G:", "\\company name\users\" & strUserDN
    >>>>
    >>>> 2. Will the mapped drives reconnect after the pc is restarted and the
    >>>> user logs in again?
    >>>>
    >>>> Any more help you could provide would be great!
    >>>>
    >>>> Regards,
    >>>>
    >>>> James
    >>>>
    >>>>
    >>>>
    >>>> "Microsoft Newsgroups" <donotreply@xxxxxx> wrote in message
    >>>> news:%23snFdrDFKHA.3964@xxxxxx
    >>>>> That is exactly what I needed. Thanks Richard!
    >>>>>
    >>>>> James
    >>>>>
    >>>>> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote
    >>>>> in message news:eD3k0prEKHA.1252@xxxxxx
    >>>>>>
    >>>>>> "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
    >>>>>> --
    >>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>
    >>
    >>
    >
    >


      My System SpecsSystem Spec

Map Network Drive problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to manage disk drive letter when conflicting with network drive ? Eric Server General 2 18 Nov 2009
Invisible network drive (Linkstation) on home network papaworx Vista networking & sharing 3 07 Dec 2008
trouble moving files from local drive to network drive dwsdad Vista networking & sharing 0 25 Feb 2008
Map a Network Drive on Vista Premium on Network Attached Storage ( OverDose Vista networking & sharing 1 18 Jan 2008
Network Mapped Drive : Lost Network Connection Ian Robert Vista networking & sharing 14 24 Aug 2007