![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | Re: Map Network Drive "Microsoft Newsgroups" <james.mcgril@xxxxxx> wrote in message news:OktkLWiEKHA.5780@xxxxxx Quote: >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 very newsgroup 9 days ago. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Map Network Drive "Microsoft Newsgroups" <james.mcgril@xxxxxx> wrote in message news:OktkLWiEKHA.5780@xxxxxx Quote: >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 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 Specs![]() |
| | #4 (permalink) |
| | 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 Quote: > > "Microsoft Newsgroups" <james.mcgril@xxxxxx> wrote in message > news:OktkLWiEKHA.5780@xxxxxx Quote: >>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 Specs![]() |
| | #5 (permalink) |
| | 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 Quote: > That is exactly what I needed. Thanks Richard! > > James > > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > message news:eD3k0prEKHA.1252@xxxxxx Quote: >> >> "Microsoft Newsgroups" <james.mcgril@xxxxxx> wrote in message >> news:OktkLWiEKHA.5780@xxxxxx Quote: >>>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 Specs![]() |
| | #6 (permalink) |
| | 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 Quote: > 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 Quote: >> That is exactly what I needed. Thanks Richard! >> >> James >> >> "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in >> message news:eD3k0prEKHA.1252@xxxxxx Quote: >>> >>> "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 Specs![]() |
| | #7 (permalink) |
| | 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 Quote: > 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 Quote: >> 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 Quote: >>> 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 Specs![]() |
| | #8 (permalink) |
| | 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 Quote: > 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 Quote: >> 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 Quote: >>> 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 Specs![]() |
| | #9 (permalink) |
| | 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 Quote: > What is the switch or argument to make the mapped drive persistant? > > James > > "James" <donotreply@xxxxxx> wrote in message > news:O6WCaBFFKHA.4316@xxxxxx Quote: >> 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 Quote: >>> 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Invisible network drive (Linkstation) on home network | Vista networking & sharing | |||
| trouble moving files from local drive to network drive | Vista networking & sharing | |||
| Map a Network Drive on Vista Premium on Network Attached Storage ( | Vista networking & sharing | |||
| Unable to map network drive because no network was found | Vista networking & sharing | |||
| Network Mapped Drive : Lost Network Connection | Vista networking & sharing | |||