![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | vb script - mapping drives help I have the following vbs script below....and it is used to map network drives based on an Active Directory User's group membership. My username is a member of the MGT IT Services group. So based on the script below, I should get the Y drive. But, not only do I get the Y drive, but for some reason, I get the "O" drive as well as the Y drive, and my username is not a part of any group that gets the O drive... On Error Resume Next Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network") strUserPath = "LDAP://" & objSysInfo.UserName Set objUser = GetObject(strUserPath) 'Removes curent mappings objNetwork.RemoveNetworkDrive "L:", True, True objNetwork.RemoveNetworkDrive "J:", True, True objNetwork.RemoveNetworkDrive "Z:", True, True objNetwork.RemoveNetworkDrive "R:", True, True objNetwork.RemoveNetworkDrive "N:", True, True objNetwork.RemoveNetworkDrive "O:", True, True objNetwork.RemoveNetworkDrive "U:", True, True objNetwork.RemoveNetworkDrive "S:", True, True objNetwork.RemoveNetworkDrive "M:", True, True objNetwork.RemoveNetworkDrive "I:", True, True objNetwork.RemoveNetworkDrive "K:", True, True objNetwork.RemoveNetworkDrive "Z:", True, True objNetwork.RemoveNetworkDrive "X:", True, True objNetwork.RemoveNetworkDrive "Y:", True, True objNetwork.RemoveNetworkDrive "Q:", True, True 'Finds users group membership 'For Each strGroup in objUser.MemberOf 'strGroupPath = "LDAP://" & strGroup 'Set objGroup = GetObject(strGroupPath) 'strGroupName = objGroup.CN If (IsMember(objUser, "MGT IT Services Group") = True) Then objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com \shares\groups\IT services", False End If If (IsMember(objUser, "MGT Career Services") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com \shares\groups\Career Services", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com \shares\groups\Career Svcs_Act", False objNetwork.MapNetworkDrive "Z:", "\\fileserver01.tgm.domain.com\com \shares\groups\Undergraduate Office", False End If If (IsMember(objUser, "MGT Career Services SAs") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com \shares\groups\Career Services", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com \shares\groups\Career Svcs_Act", False objNetwork.MapNetworkDrive "Z:", "\\fileserver01.tgm.domain.com\com \shares\groups\Undergraduate Office", False End If If (IsMember(objUser, "MGT CIBER") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com \shares\groups\CIBER", False End If If (IsMember(objUser, "MGT Communications") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com \shares\groups\Communications", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com \shares\groups\DeanSuite", False End If If (IsMember(objUser, "MGT Communications Share Guest access") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com \shares\groups\Communications", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com \shares\groups\DeanSuite", False End If If (IsMember(objUser, "MGT Dean Suite non HR") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com \shares\groups\Building Operations", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com \shares\groups\DeanSuite", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting", False objNetwork.MapNetworkDrive "U:", "\\fileserver01.tgm.domain.com\com \shares\groups\Graduate Assistantship", False objNetwork.MapNetworkDrive "S:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting\FAcS", False End If If (IsMember(objUser, "MGT Development") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com \shares\groups\Development", False objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com \shares\groups\Communications", False objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com \shares\groups\Development\Student Share", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com \shares\groups\DeanSuite", False End If If (IsMember(objUser, "MGT Development SAs") = True) Then objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com \shares\groups\Development\Student Share", False End If If (IsMember(objUser, "MGT Eview Users") = True) Then objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com \shares\groups\eview", False End If If (IsMember(objUser, "MGT Executive Masters") = True) Then objNetwork.MapNetworkDrive "I:", "\\fileserver01.tgm.domain.com\com \shares\groups\Executive Education", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com \shares\groups\EMSMOT_Act", False objNetwork.MapNetworkDrive "K:", "\\fileserver01.tgm.domain.com\com \shares\groups\EMSMOT", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting", False objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com \shares\groups\Executive Programs", False End If If (IsMember(objUser, "MGT Executive Programs") = True) Then objNetwork.MapNetworkDrive "I:", "\\fileserver01.tgm.domain.com\com \shares\groups\Executive Education", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com \shares\groups\EMSMOT_Act", False objNetwork.MapNetworkDrive "K:", "\\fileserver01.tgm.domain.com\com \shares\groups\EMSMOT", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting", False objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com \shares\groups\Executive Programs", False End If If (IsMember(objUser, "MGT Explab Share participants") = True) Then objNetwork.MapNetworkDrive "Z:", "\\fileserver01.tgm.domain.com\com \shares\groups\Explab", False End If If (IsMember(objUser, "MGT Graduate Office") = True) Then objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com \shares\groups\Graduate Office", False End If If (IsMember(objUser, "MGT Grad Assistant Share") = True) Then objNetwork.MapNetworkDrive "U:", "\\fileserver01.tgm.domain.com\com \shares\groups\Graduate Assistantship", False End If If (IsMember(objUser, "MGT HR staff") = True) Then objNetwork.MapNetworkDrive "X:", "\\fileserver01.tgm.domain.com\com \shares\groups\Building Operations", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com \shares\groups\DeanSuite", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting", False objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com \shares\groups\Communications", False objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com \shares\groups\Human Resources", False objNetwork.MapNetworkDrive "Q:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting\Pcard", False End If If (IsMember(objUser, "ILE Office") = True) Then objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com \shares\groups\Institute for LE", False End If If (IsMember(objUser, "ILE GRAs") = True) Then objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com \shares\groups\Institute for LE", False End If If (IsMember(objUser, "MGT Tiger Share participants") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com \shares\groups\Tiger", False End If If (IsMember(objUser, "MGT Undergraduate Office") = True) Then objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com \shares\groups\Undergraduate Office", False End If If (IsMember(objUser, "MGT Recruiting Share Access") = True) Then objNetwork.MapNetworkDrive "Q:", "\\fileserver01.tgm.domain.com\com \shares\groups\Recruiting", False End If If (IsMember(objUser, "MGT Faculty") = True) Then objNetwork.MapNetworkDrive "S:", "\\fileserver01.tgm.domain.com\com \shares\groups\Accounting\FAcS", False End If |
My System Specs![]() |
| | #2 (permalink) |
| | Re: vb script - mapping drives help On Nov 17, 1:50*pm, BookerT <ch...@xxxxxx> wrote: Quote: > I have the following vbs script below....and it is used to map network > drives based on an Active Directory User's group membership. *My > username is a member of the MGT IT Services group. *So based on the > script below, I should get the Y drive. * * But, not only do I get the > Y drive, but for some reason, I get the "O" drive as well as the Y > drive, and my username is not a part of any group that gets the O > drive... > > On Error Resume Next > Quote: > If (IsMember(objUser, "MGT IT Services Group") = True) Then > > *objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com > \shares\groups\IT services", False > > End If My guess is that because of the "ON Error Resume Next" at the top of your script, an error created in the IF statement above is then rippling through the rest of the script, resulting in the mapping of the "O" drive, somehow. I would recommend that you add and ON ERROR GOTO 0 line after the last RemoveNetworkDrive line so that subsequent errors will be revealed. Then you might have a better chance of finding out what is going on. Also, the long string of IF/End IF blocks are very had to troubleshoot. A better construct is the Select/Case, though in script it requires a kind of non-intuative syntax. I took the liberty of reconstructing/compressing your code below. It should be easier to debug (for me anyway ;-) ... Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network") strUserPath = "LDAP://" & objSysInfo.UserName Set objUser = GetObject(strUserPath) 'Removes current mappings sDrvList = "I: J: K: L: M: N: O: Q: R: S: U: X: Y: Z:" with objNetwork On Error Resume Next for each sDrv in Split(sDrvList) .RemoveNetworkDrive sDrv, True, True next On Error Goto 0 end with ' objNetwork 'Finds users group membership 'For Each strGroup in objUser.MemberOf 'strGroupPath = "LDAP://" & strGroup 'Set objGroup = GetObject(strGroupPath) 'strGroupName = objGroup.CN strSharePath = "\\fileserver01.tgm.domain.com\com\shares\groups" Select case True Case IsMember(objUser, "MGT IT Services Group") objNetwork.MapNetworkDrive "Y:", _ strSharePath & "\IT services", False Case IsMember(objUser, "MGT Career Services") or _ IsMember(objUser, "MGT Career Services SAs") objNetwork.MapNetworkDrive "L:", _ strSharePath & "\Career Services", False objNetwork.MapNetworkDrive "J:", _ strSharePath & "\Career Svcs_Act", False objNetwork.MapNetworkDrive "Z:", strSharePath & "\Undergraduate Office", False Case IsMember(objUser, "MGT CIBER") objNetwork.MapNetworkDrive "R:", _ "strSharePath & "\CIBER", False Case IsMember(objUser, "MGT Communications") or _ IsMember(objUser, "MGT Communications Share Guest access") objNetwork.MapNetworkDrive "N:", _ "strSharePath & "\DeanSuite", False objNetwork.MapNetworkDrive "R:", _ "strSharePath & "\Communications", False Case IsMember(objUser, "MGT Dean Suite non HR") objNetwork.MapNetworkDrive "L:", _ "strSharePath & "\Building Operations", False objNetwork.MapNetworkDrive "N:", _ "strSharePath & "\DeanSuite", False objNetwork.MapNetworkDrive "O:", _ "strSharePath & "\Accounting", False objNetwork.MapNetworkDrive "S:", _ "strSharePath & "\Accounting\FAcS", False objNetwork.MapNetworkDrive "U:", _ "strSharePath & "\Graduate Assistantship", False Case IsMember(objUser, "MGT Development") objNetwork.MapNetworkDrive "L:", _ "strSharePath & "\Development", False objNetwork.MapNetworkDrive "M:", _ "strSharePath & "\Development\Student Share", False objNetwork.MapNetworkDrive "N:", _ "strSharePath & "\DeanSuite", False objNetwork.MapNetworkDrive "R:", _ "strSharePath & "\Communications", False Case IsMember(objUser, "MGT Development SAs") objNetwork.MapNetworkDrive "M:", _ "strSharePath & "\Development\Student Share", False Case IsMember(objUser, "MGT Eview Users") objNetwork.MapNetworkDrive "Y:", _ "strSharePath & "\eview", False Case IsMember(objUser, "MGT Executive Masters") or _ IsMember(objUser, "MGT Executive Programs") objNetwork.MapNetworkDrive "I:", _ "strSharePath & "\Executive Education", False objNetwork.MapNetworkDrive "J:", _ "strSharePath & "\EMSMOT_Act", False objNetwork.MapNetworkDrive "K:", _ "strSharePath & "\EMSMOT", False objNetwork.MapNetworkDrive "O:", _ "strSharePath & "\Accounting", False objNetwork.MapNetworkDrive "L:", _ "strSharePath & "\Executive Programs", False Case IsMember(objUser, "MGT Explab Share participants") objNetwork.MapNetworkDrive "Z:", _ "strSharePath & "\Explab", False Case IsMember(objUser, "MGT Graduate Office") objNetwork.MapNetworkDrive "M:", _ "strSharePath & "\Graduate Office", False Case IsMember(objUser, "MGT Grad Assistant Share") objNetwork.MapNetworkDrive "U:", _ "strSharePath & "\Graduate Assistantship", False Case IsMember(objUser, "MGT HR staff") objNetwork.MapNetworkDrive "X:", _ "strSharePath & "\Building Operations", False objNetwork.MapNetworkDrive "N:", _ "strSharePath & "\DeanSuite", False objNetwork.MapNetworkDrive "O:", _ "strSharePath & "\Accounting", False objNetwork.MapNetworkDrive "Y:", _ "strSharePath & "\Communications", False objNetwork.MapNetworkDrive "R:", _ "strSharePath & "\Human Resources", False objNetwork.MapNetworkDrive "Q:", _ "strSharePath & "\Accounting\Pcard", False Case IsMember(objUser, "ILE Office") or _ IsMember(objUser, "ILE GRAs") objNetwork.MapNetworkDrive "J:", _ "strSharePath & "\Institute for LE", False Case IsMember(objUser, "MGT Tiger Share participants") objNetwork.MapNetworkDrive "R:", _ "strSharePath & "\Tiger", False Case IsMember(objUser, "MGT Undergraduate Office") objNetwork.MapNetworkDrive "M:", _ "strSharePath & "\Undergraduate Office", False Case IsMember(objUser, "MGT Recruiting Share Access") objNetwork.MapNetworkDrive "Q:", _ "strSharePath & "\Recruiting", False Case IsMember(objUser, "MGT Faculty") objNetwork.MapNetworkDrive "S:", _ "strSharePath & "\Accounting\FAcS", False end Select HTH, Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
| | #3 (permalink) |
| | Re: vb script - mapping drives help On Nov 17, 4:28*pm, Tom Lavedas <tglba...@xxxxxx> wrote: Quote: > On Nov 17, 1:50*pm, BookerT <ch...@xxxxxx> wrote: > Quote: > > I have the following vbs script below....and it is used to map network > > drives based on an Active Directory User's group membership. *My > > username is a member of the MGT IT Services group. *So based on the > > script below, I should get the Y drive. * * But, not only do I get the > > Y drive, but for some reason, I get the "O" drive as well as the Y > > drive, and my username is not a part of any group that gets the O > > drive... Quote: > > On Error Resume Next > {snip} > Quote: > > If (IsMember(objUser, "MGT IT Services Group") = True) Then Quote: > > *objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com > > \shares\groups\IT services", False Quote: > > End If > {snip} > > My guess is that because of the "ON Error Resume Next" at the top of > your script, an error created in the IF statement above is then > rippling through the rest of the script, resulting in the mapping of > the "O" drive, somehow. > > I would recommend that you add and ON ERROR GOTO 0 line after the last > RemoveNetworkDrive line so that subsequent errors will be revealed. > Then you might have a better chance of finding out what is going on. > > Also, the long string of IF/End IF blocks are very had to > troubleshoot. *A better construct is the Select/Case, though in script > it requires a kind of non-intuative syntax. *I took the liberty of > reconstructing/compressing your code below. *It should be easier to > debug (for me anyway ;-) ... > > Set objSysInfo = CreateObject("ADSystemInfo") > Set objNetwork = CreateObject("Wscript.Network") > strUserPath = "LDAP://" & objSysInfo.UserName > Set objUser = GetObject(strUserPath) > > 'Removes current mappings > sDrvList = "I: J: K: L: M: N: O: Q: R: S: U: X: Y: Z:" > with objNetwork > * On Error Resume Next > * for each sDrv in Split(sDrvList) > * * .RemoveNetworkDrive sDrv, True, True > * next > * On Error Goto 0 > end with ' objNetwork > > 'Finds users group membership > 'For Each strGroup in objUser.MemberOf > 'strGroupPath = "LDAP://" & strGroup > 'Set objGroup = GetObject(strGroupPath) > 'strGroupName = objGroup.CN > > strSharePath = "\\fileserver01.tgm.domain.com\com\shares\groups" > > Select case True > * Case IsMember(objUser, "MGT IT Services Group") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * strSharePath & "\IT services", False > > * Case IsMember(objUser, "MGT Career Services") or _ > * * * *IsMember(objUser, "MGT Career Services SAs") > * * objNetwork.MapNetworkDrive "L:", _ > * * * strSharePath & "\Career Services", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * strSharePath & "\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > * * * strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT CIBER") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\CIBER", False > > * Case IsMember(objUser, "MGT Communications") or _ > * * * *IsMember(objUser, "MGT Communications Share Guest access") > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Dean Suite non HR") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT Development") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Development", False > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Development SAs") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > > * Case IsMember(objUser, "MGT Eview Users") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\eview", False > > * Case IsMember(objUser, "MGT Executive Masters") or _ > * * * *IsMember(objUser, "MGT Executive Programs") > * * objNetwork.MapNetworkDrive "I:", _ > * * * "strSharePath & "\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", _ > * * * "strSharePath & "\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Executive Programs", False > > * Case IsMember(objUser, "MGT Explab Share participants") > * * objNetwork.MapNetworkDrive "Z:", _ > * * * "strSharePath & "\Explab", False > > * Case IsMember(objUser, "MGT Graduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Graduate Office", False > > * Case IsMember(objUser, "MGT Grad Assistant Share") > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT HR staff") > * * objNetwork.MapNetworkDrive "X:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\Communications", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Human Resources", False > * * objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Accounting\Pcard", False > > * Case IsMember(objUser, "ILE Office") or _ > * * * *IsMember(objUser, "ILE GRAs") > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\Institute for LE", False > > * Case IsMember(objUser, "MGT Tiger Share participants") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Tiger", False > > * Case IsMember(objUser, "MGT Undergraduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT Recruiting Share Access") > * * *objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Recruiting", False > > * Case IsMember(objUser, "MGT Faculty") > * * *objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > > *end Select > > HTH, > > Tom Lavedas > ***********http://there.is.no.more/tglbatch/ was trying to avoid, if possible, slowing down the execution of the script if possible. I will try your suggesstions. Thanks |
My System Specs![]() |
| | #4 (permalink) |
| | Re: vb script - mapping drives help On Nov 17, 4:28*pm, Tom Lavedas <tglba...@xxxxxx> wrote: Quote: > On Nov 17, 1:50*pm, BookerT <ch...@xxxxxx> wrote: > Quote: > > I have the following vbs script below....and it is used to map network > > drives based on an Active Directory User's group membership. *My > > username is a member of the MGT IT Services group. *So based on the > > script below, I should get the Y drive. * * But, not only do I get the > > Y drive, but for some reason, I get the "O" drive as well as the Y > > drive, and my username is not a part of any group that gets the O > > drive... Quote: > > On Error Resume Next > {snip} > Quote: > > If (IsMember(objUser, "MGT IT Services Group") = True) Then Quote: > > *objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com > > \shares\groups\IT services", False Quote: > > End If > {snip} > > My guess is that because of the "ON Error Resume Next" at the top of > your script, an error created in the IF statement above is then > rippling through the rest of the script, resulting in the mapping of > the "O" drive, somehow. > > I would recommend that you add and ON ERROR GOTO 0 line after the last > RemoveNetworkDrive line so that subsequent errors will be revealed. > Then you might have a better chance of finding out what is going on. > > Also, the long string of IF/End IF blocks are very had to > troubleshoot. *A better construct is the Select/Case, though in script > it requires a kind of non-intuative syntax. *I took the liberty of > reconstructing/compressing your code below. *It should be easier to > debug (for me anyway ;-) ... > > Set objSysInfo = CreateObject("ADSystemInfo") > Set objNetwork = CreateObject("Wscript.Network") > strUserPath = "LDAP://" & objSysInfo.UserName > Set objUser = GetObject(strUserPath) > > 'Removes current mappings > sDrvList = "I: J: K: L: M: N: O: Q: R: S: U: X: Y: Z:" > with objNetwork > * On Error Resume Next > * for each sDrv in Split(sDrvList) > * * .RemoveNetworkDrive sDrv, True, True > * next > * On Error Goto 0 > end with ' objNetwork > > 'Finds users group membership > 'For Each strGroup in objUser.MemberOf > 'strGroupPath = "LDAP://" & strGroup > 'Set objGroup = GetObject(strGroupPath) > 'strGroupName = objGroup.CN > > strSharePath = "\\fileserver01.tgm.domain.com\com\shares\groups" > > Select case True > * Case IsMember(objUser, "MGT IT Services Group") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * strSharePath & "\IT services", False > > * Case IsMember(objUser, "MGT Career Services") or _ > * * * *IsMember(objUser, "MGT Career Services SAs") > * * objNetwork.MapNetworkDrive "L:", _ > * * * strSharePath & "\Career Services", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * strSharePath & "\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > * * * strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT CIBER") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\CIBER", False > > * Case IsMember(objUser, "MGT Communications") or _ > * * * *IsMember(objUser, "MGT Communications Share Guest access") > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Dean Suite non HR") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT Development") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Development", False > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Development SAs") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > > * Case IsMember(objUser, "MGT Eview Users") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\eview", False > > * Case IsMember(objUser, "MGT Executive Masters") or _ > * * * *IsMember(objUser, "MGT Executive Programs") > * * objNetwork.MapNetworkDrive "I:", _ > * * * "strSharePath & "\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", _ > * * * "strSharePath & "\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Executive Programs", False > > * Case IsMember(objUser, "MGT Explab Share participants") > * * objNetwork.MapNetworkDrive "Z:", _ > * * * "strSharePath & "\Explab", False > > * Case IsMember(objUser, "MGT Graduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Graduate Office", False > > * Case IsMember(objUser, "MGT Grad Assistant Share") > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT HR staff") > * * objNetwork.MapNetworkDrive "X:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\Communications", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Human Resources", False > * * objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Accounting\Pcard", False > > * Case IsMember(objUser, "ILE Office") or _ > * * * *IsMember(objUser, "ILE GRAs") > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\Institute for LE", False > > * Case IsMember(objUser, "MGT Tiger Share participants") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Tiger", False > > * Case IsMember(objUser, "MGT Undergraduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT Recruiting Share Access") > * * *objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Recruiting", False > > * Case IsMember(objUser, "MGT Faculty") > * * *objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > > *end Select > > HTH, > > Tom Lavedas > ***********http://there.is.no.more/tglbatch/ script error when logging on Line: 40 Char: 38 Error: Syntax Error Code: 800A03EA Source: Microsoft VBScript compilation error |
My System Specs![]() |
| | #5 (permalink) |
| | Re: vb script - mapping drives help On Nov 17, 4:28*pm, Tom Lavedas <tglba...@xxxxxx> wrote: Quote: > On Nov 17, 1:50*pm, BookerT <ch...@xxxxxx> wrote: > Quote: > > I have the following vbs script below....and it is used to map network > > drives based on an Active Directory User's group membership. *My > > username is a member of the MGT IT Services group. *So based on the > > script below, I should get the Y drive. * * But, not only do I get the > > Y drive, but for some reason, I get the "O" drive as well as the Y > > drive, and my username is not a part of any group that gets the O > > drive... Quote: > > On Error Resume Next > {snip} > Quote: > > If (IsMember(objUser, "MGT IT Services Group") = True) Then Quote: > > *objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com > > \shares\groups\IT services", False Quote: > > End If > {snip} > > My guess is that because of the "ON Error Resume Next" at the top of > your script, an error created in the IF statement above is then > rippling through the rest of the script, resulting in the mapping of > the "O" drive, somehow. > > I would recommend that you add and ON ERROR GOTO 0 line after the last > RemoveNetworkDrive line so that subsequent errors will be revealed. > Then you might have a better chance of finding out what is going on. > > Also, the long string of IF/End IF blocks are very had to > troubleshoot. *A better construct is the Select/Case, though in script > it requires a kind of non-intuative syntax. *I took the liberty of > reconstructing/compressing your code below. *It should be easier to > debug (for me anyway ;-) ... > > Set objSysInfo = CreateObject("ADSystemInfo") > Set objNetwork = CreateObject("Wscript.Network") > strUserPath = "LDAP://" & objSysInfo.UserName > Set objUser = GetObject(strUserPath) > > 'Removes current mappings > sDrvList = "I: J: K: L: M: N: O: Q: R: S: U: X: Y: Z:" > with objNetwork > * On Error Resume Next > * for each sDrv in Split(sDrvList) > * * .RemoveNetworkDrive sDrv, True, True > * next > * On Error Goto 0 > end with ' objNetwork > > 'Finds users group membership > 'For Each strGroup in objUser.MemberOf > 'strGroupPath = "LDAP://" & strGroup > 'Set objGroup = GetObject(strGroupPath) > 'strGroupName = objGroup.CN > > strSharePath = "\\fileserver01.tgm.domain.com\com\shares\groups" > > Select case True > * Case IsMember(objUser, "MGT IT Services Group") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * strSharePath & "\IT services", False > > * Case IsMember(objUser, "MGT Career Services") or _ > * * * *IsMember(objUser, "MGT Career Services SAs") > * * objNetwork.MapNetworkDrive "L:", _ > * * * strSharePath & "\Career Services", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * strSharePath & "\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > * * * strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT CIBER") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\CIBER", False > > * Case IsMember(objUser, "MGT Communications") or _ > * * * *IsMember(objUser, "MGT Communications Share Guest access") > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Dean Suite non HR") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT Development") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Development", False > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Development SAs") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > > * Case IsMember(objUser, "MGT Eview Users") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\eview", False > > * Case IsMember(objUser, "MGT Executive Masters") or _ > * * * *IsMember(objUser, "MGT Executive Programs") > * * objNetwork.MapNetworkDrive "I:", _ > * * * "strSharePath & "\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", _ > * * * "strSharePath & "\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Executive Programs", False > > * Case IsMember(objUser, "MGT Explab Share participants") > * * objNetwork.MapNetworkDrive "Z:", _ > * * * "strSharePath & "\Explab", False > > * Case IsMember(objUser, "MGT Graduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Graduate Office", False > > * Case IsMember(objUser, "MGT Grad Assistant Share") > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT HR staff") > * * objNetwork.MapNetworkDrive "X:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\Communications", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Human Resources", False > * * objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Accounting\Pcard", False > > * Case IsMember(objUser, "ILE Office") or _ > * * * *IsMember(objUser, "ILE GRAs") > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\Institute for LE", False > > * Case IsMember(objUser, "MGT Tiger Share participants") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Tiger", False > > * Case IsMember(objUser, "MGT Undergraduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT Recruiting Share Access") > * * *objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Recruiting", False > > * Case IsMember(objUser, "MGT Faculty") > * * *objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > > *end Select > > HTH, > > Tom Lavedas > ***********http://there.is.no.more/tglbatch/ but then, my username should not have been a member of this group, so this case should have been false.... Case IsMember(objUser, "MGT Career Services") or _ IsMember(objUser, "MGT Career Services SAs") objNetwork.MapNetworkDrive "L:", _ strSharePath & "\Career Services", False objNetwork.MapNetworkDrive "J:", _ strSharePath & "\Career Svcs_Act", False objNetwork.MapNetworkDrive "Z:", strSharePath & "\Undergraduate Office", False |
My System Specs![]() |
| | #6 (permalink) |
| | Re: vb script - mapping drives help On Nov 17, 4:28*pm, Tom Lavedas <tglba...@xxxxxx> wrote: Quote: > On Nov 17, 1:50*pm, BookerT <ch...@xxxxxx> wrote: > Quote: > > I have the following vbs script below....and it is used to map network > > drives based on an Active Directory User's group membership. *My > > username is a member of the MGT IT Services group. *So based on the > > script below, I should get the Y drive. * * But, not only do I get the > > Y drive, but for some reason, I get the "O" drive as well as the Y > > drive, and my username is not a part of any group that gets the O > > drive... Quote: > > On Error Resume Next > {snip} > Quote: > > If (IsMember(objUser, "MGT IT Services Group") = True) Then Quote: > > *objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com > > \shares\groups\IT services", False Quote: > > End If > {snip} > > My guess is that because of the "ON Error Resume Next" at the top of > your script, an error created in the IF statement above is then > rippling through the rest of the script, resulting in the mapping of > the "O" drive, somehow. > > I would recommend that you add and ON ERROR GOTO 0 line after the last > RemoveNetworkDrive line so that subsequent errors will be revealed. > Then you might have a better chance of finding out what is going on. > > Also, the long string of IF/End IF blocks are very had to > troubleshoot. *A better construct is the Select/Case, though in script > it requires a kind of non-intuative syntax. *I took the liberty of > reconstructing/compressing your code below. *It should be easier to > debug (for me anyway ;-) ... > > Set objSysInfo = CreateObject("ADSystemInfo") > Set objNetwork = CreateObject("Wscript.Network") > strUserPath = "LDAP://" & objSysInfo.UserName > Set objUser = GetObject(strUserPath) > > 'Removes current mappings > sDrvList = "I: J: K: L: M: N: O: Q: R: S: U: X: Y: Z:" > with objNetwork > * On Error Resume Next > * for each sDrv in Split(sDrvList) > * * .RemoveNetworkDrive sDrv, True, True > * next > * On Error Goto 0 > end with ' objNetwork > > 'Finds users group membership > 'For Each strGroup in objUser.MemberOf > 'strGroupPath = "LDAP://" & strGroup > 'Set objGroup = GetObject(strGroupPath) > 'strGroupName = objGroup.CN > > strSharePath = "\\fileserver01.tgm.domain.com\com\shares\groups" > > Select case True > * Case IsMember(objUser, "MGT IT Services Group") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * strSharePath & "\IT services", False > > * Case IsMember(objUser, "MGT Career Services") or _ > * * * *IsMember(objUser, "MGT Career Services SAs") > * * objNetwork.MapNetworkDrive "L:", _ > * * * strSharePath & "\Career Services", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * strSharePath & "\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > * * * strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT CIBER") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\CIBER", False > > * Case IsMember(objUser, "MGT Communications") or _ > * * * *IsMember(objUser, "MGT Communications Share Guest access") > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Dean Suite non HR") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT Development") > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Development", False > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Communications", False > > * Case IsMember(objUser, "MGT Development SAs") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Development\Student Share", False > > * Case IsMember(objUser, "MGT Eview Users") > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\eview", False > > * Case IsMember(objUser, "MGT Executive Masters") or _ > * * * *IsMember(objUser, "MGT Executive Programs") > * * objNetwork.MapNetworkDrive "I:", _ > * * * "strSharePath & "\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", _ > * * * "strSharePath & "\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "L:", _ > * * * "strSharePath & "\Executive Programs", False > > * Case IsMember(objUser, "MGT Explab Share participants") > * * objNetwork.MapNetworkDrive "Z:", _ > * * * "strSharePath & "\Explab", False > > * Case IsMember(objUser, "MGT Graduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Graduate Office", False > > * Case IsMember(objUser, "MGT Grad Assistant Share") > * * objNetwork.MapNetworkDrive "U:", _ > * * * "strSharePath & "\Graduate Assistantship", False > > * Case IsMember(objUser, "MGT HR staff") > * * objNetwork.MapNetworkDrive "X:", _ > * * * "strSharePath & "\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", _ > * * * "strSharePath & "\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", _ > * * * "strSharePath & "\Accounting", False > * * objNetwork.MapNetworkDrive "Y:", _ > * * * "strSharePath & "\Communications", False > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Human Resources", False > * * objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Accounting\Pcard", False > > * Case IsMember(objUser, "ILE Office") or _ > * * * *IsMember(objUser, "ILE GRAs") > * * objNetwork.MapNetworkDrive "J:", _ > * * * "strSharePath & "\Institute for LE", False > > * Case IsMember(objUser, "MGT Tiger Share participants") > * * objNetwork.MapNetworkDrive "R:", _ > * * * "strSharePath & "\Tiger", False > > * Case IsMember(objUser, "MGT Undergraduate Office") > * * objNetwork.MapNetworkDrive "M:", _ > * * * "strSharePath & "\Undergraduate Office", False > > * Case IsMember(objUser, "MGT Recruiting Share Access") > * * *objNetwork.MapNetworkDrive "Q:", _ > * * * "strSharePath & "\Recruiting", False > > * Case IsMember(objUser, "MGT Faculty") > * * *objNetwork.MapNetworkDrive "S:", _ > * * * "strSharePath & "\Accounting\FAcS", False > > *end Select > > HTH, > > Tom Lavedas > ***********http://there.is.no.more/tglbatch/ from before the strSharepath variable locations, but now when I logon, it gave me a Type mismatch: 'Ismember' error. Code: 800A000D |
My System Specs![]() |
| | #7 (permalink) |
| | Re: vb script - mapping drives help On Nov 18, 3:47*pm, BookerT <ch...@xxxxxx> wrote: Quote: > On Nov 17, 4:28*pm, Tom Lavedas <tglba...@xxxxxx> wrote: > > > Quote: > > On Nov 17, 1:50*pm, BookerT <ch...@xxxxxx> wrote: Quote: Quote: > > > I have the following vbs script below....and it is used to map network > > > drives based on an Active Directory User's group membership. *My > > > username is a member of the MGT IT Services group. *So based on the > > > script below, I should get the Y drive. * * But, not only do I get the > > > Y drive, but for some reason, I get the "O" drive as well as the Y > > > drive, and my username is not a part of any group that gets the O > > > drive... Quote: Quote: > > > On Error Resume Next Quote: > > {snip} Quote: Quote: > > > If (IsMember(objUser, "MGT IT Services Group") = True) Then Quote: Quote: > > > *objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com > > > \shares\groups\IT services", False Quote: Quote: > > > End If Quote: > > {snip} Quote: > > My guess is that because of the "ON Error Resume Next" at the top of > > your script, an error created in the IF statement above is then > > rippling through the rest of the script, resulting in the mapping of > > the "O" drive, somehow. Quote: > > I would recommend that you add and ON ERROR GOTO 0 line after the last > > RemoveNetworkDrive line so that subsequent errors will be revealed. > > Then you might have a better chance of finding out what is going on. Quote: > > Also, the long string of IF/End IF blocks are very had to > > troubleshoot. *A better construct is the Select/Case, though in script > > it requires a kind of non-intuative syntax. *I took the liberty of > > reconstructing/compressing your code below. *It should be easier to > > debug (for me anyway ;-) ... Quote: > > Set objSysInfo = CreateObject("ADSystemInfo") > > Set objNetwork = CreateObject("Wscript.Network") > > strUserPath = "LDAP://" & objSysInfo.UserName > > Set objUser = GetObject(strUserPath) Quote: > > 'Removes current mappings > > sDrvList = "I: J: K: L: M: N: O: Q: R: S: U: X: Y: Z:" > > with objNetwork > > * On Error Resume Next > > * for each sDrv in Split(sDrvList) > > * * .RemoveNetworkDrive sDrv, True, True > > * next > > * On Error Goto 0 > > end with ' objNetwork Quote: > > 'Finds users group membership > > 'For Each strGroup in objUser.MemberOf > > 'strGroupPath = "LDAP://" & strGroup > > 'Set objGroup = GetObject(strGroupPath) > > 'strGroupName = objGroup.CN Quote: > > strSharePath = "\\fileserver01.tgm.domain.com\com\shares\groups" Quote: > > Select case True > > * Case IsMember(objUser, "MGT IT Services Group") > > * * objNetwork.MapNetworkDrive "Y:", _ > > * * * strSharePath & "\IT services", False Quote: > > * Case IsMember(objUser, "MGT Career Services") or _ > > * * * *IsMember(objUser, "MGT Career Services SAs") > > * * objNetwork.MapNetworkDrive "L:", _ > > * * * strSharePath & "\Career Services", False > > * * objNetwork.MapNetworkDrive "J:", _ > > * * * strSharePath & "\Career Svcs_Act", False > > * * objNetwork.MapNetworkDrive "Z:", > > * * * strSharePath & "\Undergraduate Office", False Quote: > > * Case IsMember(objUser, "MGT CIBER") > > * * objNetwork.MapNetworkDrive "R:", _ > > * * * "strSharePath & "\CIBER", False Quote: > > * Case IsMember(objUser, "MGT Communications") or _ > > * * * *IsMember(objUser, "MGT Communications Share Guest access") > > * * objNetwork.MapNetworkDrive "N:", _ > > * * * "strSharePath & "\DeanSuite", False > > * * objNetwork.MapNetworkDrive "R:", _ > > * * * "strSharePath & "\Communications", False Quote: > > * Case IsMember(objUser, "MGT Dean Suite non HR") > > * * objNetwork.MapNetworkDrive "L:", _ > > * * * "strSharePath & "\Building Operations", False > > * * objNetwork.MapNetworkDrive "N:", _ > > * * * "strSharePath & "\DeanSuite", False > > * * objNetwork.MapNetworkDrive "O:", _ > > * * * "strSharePath & "\Accounting", False > > * * objNetwork.MapNetworkDrive "S:", _ > > * * * "strSharePath & "\Accounting\FAcS", False > > * * objNetwork.MapNetworkDrive "U:", _ > > * * * "strSharePath & "\Graduate Assistantship", False Quote: > > * Case IsMember(objUser, "MGT Development") > > * * objNetwork.MapNetworkDrive "L:", _ > > * * * "strSharePath & "\Development", False > > * * objNetwork.MapNetworkDrive "M:", _ > > * * * "strSharePath & "\Development\Student Share", False > > * * objNetwork.MapNetworkDrive "N:", _ > > * * * "strSharePath & "\DeanSuite", False > > * * objNetwork.MapNetworkDrive "R:", _ > > * * * "strSharePath & "\Communications", False Quote: > > * Case IsMember(objUser, "MGT Development SAs") > > * * objNetwork.MapNetworkDrive "M:", _ > > * * * "strSharePath & "\Development\Student Share", False Quote: > > * Case IsMember(objUser, "MGT Eview Users") > > * * objNetwork.MapNetworkDrive "Y:", _ > > * * * "strSharePath & "\eview", False Quote: > > * Case IsMember(objUser, "MGT Executive Masters") or _ > > * * * *IsMember(objUser, "MGT Executive Programs") > > * * objNetwork.MapNetworkDrive "I:", _ > > * * * "strSharePath & "\Executive Education", False > > * * objNetwork.MapNetworkDrive "J:", _ > > * * * "strSharePath & "\EMSMOT_Act", False > > * * objNetwork.MapNetworkDrive "K:", _ > > * * * "strSharePath & "\EMSMOT", False > > * * objNetwork.MapNetworkDrive "O:", _ > > * * * "strSharePath & "\Accounting", False > > * * objNetwork.MapNetworkDrive "L:", _ > > * * * "strSharePath & "\Executive Programs", False Quote: > > * Case IsMember(objUser, "MGT Explab Share participants") > > * * objNetwork.MapNetworkDrive "Z:", _ > > * * * "strSharePath & "\Explab", False Quote: > > * Case IsMember(objUser, "MGT Graduate Office") > > * * objNetwork.MapNetworkDrive "M:", _ > > * * * "strSharePath & "\Graduate Office", False Quote: > > * Case IsMember(objUser, "MGT Grad Assistant Share") > > * * objNetwork.MapNetworkDrive "U:", _ > > * * * "strSharePath & "\Graduate Assistantship", False Quote: > > * Case IsMember(objUser, "MGT HR staff") > > * * objNetwork.MapNetworkDrive "X:", _ > > * * * "strSharePath & "\Building Operations", False > > * * objNetwork.MapNetworkDrive "N:", _ > > * * * "strSharePath & "\DeanSuite", False > > * * objNetwork.MapNetworkDrive "O:", _ > > * * * "strSharePath & "\Accounting", False > > * * objNetwork.MapNetworkDrive "Y:", _ > > * * * "strSharePath & "\Communications", False > > * * objNetwork.MapNetworkDrive "R:", _ > > * * * "strSharePath & "\Human Resources", False > > * * objNetwork.MapNetworkDrive "Q:", _ > > * * * "strSharePath & "\Accounting\Pcard", False Quote: > > * Case IsMember(objUser, "ILE Office") or _ > > * * * *IsMember(objUser, "ILE GRAs") > > * * objNetwork.MapNetworkDrive "J:", _ > > * * * "strSharePath & "\Institute for LE", False Quote: > > * Case IsMember(objUser, "MGT Tiger Share participants") > > * * objNetwork.MapNetworkDrive "R:", _ > > * * * "strSharePath & "\Tiger", False Quote: > > * Case IsMember(objUser, "MGT Undergraduate Office") > > * * objNetwork.MapNetworkDrive "M:", _ > > * * * "strSharePath & "\Undergraduate Office", False Quote: > > * Case IsMember(objUser, "MGT Recruiting Share Access") > > * * *objNetwork.MapNetworkDrive "Q:", _ > > * * * "strSharePath & "\Recruiting", False Quote: > > * Case IsMember(objUser, "MGT Faculty") > > * * *objNetwork.MapNetworkDrive "S:", _ > > * * * "strSharePath & "\Accounting\FAcS", False Quote: > > *end Select Quote: > > HTH, Quote: > Ok, I think i have all of the syntax errors fixed. *I removed the " > from before the strSharepath variable locations, but now when I logon, > it gave me *a Type mismatch: 'Ismember' error. *Code: 800A000D expertise. However, the problem you are having is that your script is missing the ISMember() function code. Maybe Mr. Mueller's site will help. Specifically try: http://www.rlmueller.net/IsMember8.htm Tom Lavedas *********** http://there.is.no.more/tglbatch/ |
My System Specs![]() |
| | #8 (permalink) |
| | Re: vb script - mapping drives help Code similar to below works for me: =============== Option Explicit Dim objSysInfo, objNetwork, strUserPath, objUser Dim adoCommand, adoConnection, strBase, strAttributes Dim objGroupList Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("Wscript.Network") strUserPath = "LDAP://" & objSysInfo.UserName Set objUser = GetObject(strUserPath) 'Removes curent mappings On Error Resume Next objNetwork.RemoveNetworkDrive "L:", True, True objNetwork.RemoveNetworkDrive "J:", True, True objNetwork.RemoveNetworkDrive "Z:", True, True objNetwork.RemoveNetworkDrive "R:", True, True objNetwork.RemoveNetworkDrive "N:", True, True objNetwork.RemoveNetworkDrive "O:", True, True objNetwork.RemoveNetworkDrive "U:", True, True objNetwork.RemoveNetworkDrive "S:", True, True objNetwork.RemoveNetworkDrive "M:", True, True objNetwork.RemoveNetworkDrive "I:", True, True objNetwork.RemoveNetworkDrive "K:", True, True objNetwork.RemoveNetworkDrive "Z:", True, True objNetwork.RemoveNetworkDrive "X:", True, True objNetwork.RemoveNetworkDrive "Y:", True, True objNetwork.RemoveNetworkDrive "Q:", True, True On Error GoTo 0 If (IsMember(objUser, "MGT IT Services Group") = True) Then objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com\shares\groups\IT services", False End If If (IsMember(objUser, "MGT Career Services") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com\shares\groups\Career Services", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com\shares\groups\Career Svcs_Act", False objNetwork.MapNetworkDrive "Z:", "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", False End If If (IsMember(objUser, "MGT Career Services SAs") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com\shares\groups\Career Services", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com\shares\groups\Career Svcs_Act", False objNetwork.MapNetworkDrive "Z:", "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", False End If If (IsMember(objUser, "MGT CIBER") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com\shares\groups\CIBER", False End If If (IsMember(objUser, "MGT Communications") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False End If If (IsMember(objUser, "MGT Communications Share Guest access") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False End If If (IsMember(objUser, "MGT Dean Suite non HR") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com\shares\groups\Building Operations", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False objNetwork.MapNetworkDrive "U:", "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Assistantship", False objNetwork.MapNetworkDrive "S:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\FAcS", False End If If (IsMember(objUser, "MGT Development") = True) Then objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com\shares\groups\Development", False objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com\shares\groups\Development\Student Share", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False End If If (IsMember(objUser, "MGT Development SAs") = True) Then objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com\shares\groups\Development\Student Share", False End If If (IsMember(objUser, "MGT Eview Users") = True) Then objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com\shares\groups\eview", False End If If (IsMember(objUser, "MGT Executive Masters") = True) Then objNetwork.MapNetworkDrive "I:", "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Education", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT_Act", False objNetwork.MapNetworkDrive "K:", "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Programs", False End If If (IsMember(objUser, "MGT Executive Programs") = True) Then objNetwork.MapNetworkDrive "I:", "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Education", False objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT_Act", False objNetwork.MapNetworkDrive "K:", "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False objNetwork.MapNetworkDrive "L:", "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Programs", False End If If (IsMember(objUser, "MGT Explab Share participants") = True) Then objNetwork.MapNetworkDrive "Z:", "\\fileserver01.tgm.domain.com\com\shares\groups\Explab", False End If If (IsMember(objUser, "MGT Graduate Office") = True) Then objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Office", False End If If (IsMember(objUser, "MGT Grad Assistant Share") = True) Then objNetwork.MapNetworkDrive "U:", "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Assistantship", False End If If (IsMember(objUser, "MGT HR staff") = True) Then objNetwork.MapNetworkDrive "X:", "\\fileserver01.tgm.domain.com\com\shares\groups\Building Operations", False objNetwork.MapNetworkDrive "N:", "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False objNetwork.MapNetworkDrive "O:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False objNetwork.MapNetworkDrive "Y:", "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com\shares\groups\Human Resources", False objNetwork.MapNetworkDrive "Q:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\Pcard", False End If If (IsMember(objUser, "ILE Office") = True) Then objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com\shares\groups\Institute for LE", False End If If (IsMember(objUser, "ILE GRAs") = True) Then objNetwork.MapNetworkDrive "J:", "\\fileserver01.tgm.domain.com\com\shares\groups\Institute for LE", False End If If (IsMember(objUser, "MGT Tiger Share participants") = True) Then objNetwork.MapNetworkDrive "R:", "\\fileserver01.tgm.domain.com\com\shares\groups\Tiger", False End If If (IsMember(objUser, "MGT Undergraduate Office") = True) Then objNetwork.MapNetworkDrive "M:", "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", False End If If (IsMember(objUser, "MGT Recruiting Share Access") = True) Then objNetwork.MapNetworkDrive "Q:", "\\fileserver01.tgm.domain.com\com\shares\groups\Recruiting", False End If If (IsMember(objUser, "MGT Faculty") = True) Then objNetwork.MapNetworkDrive "S:", "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\FAcS", False End If Function IsMember(ByVal objADObject, ByVal strGroupNTName) ' Function to test for group membership. ' objADObject is a user or computer object. ' strGroupNTName is the NT name (sAMAccountName) of the group to test. ' objGroupList is a dictionary object, with global scope. ' Returns True if the user or computer is a member of the group. ' Subroutine LoadGroups is called once for each different objADObject. Dim objRootDSE, strDNSDomain ' The first time IsMember is called, setup the dictionary object ' and objects required for ADO. If (IsEmpty(objGroupList) = True) Then Set objGroupList = CreateObject("Scripting.Dictionary") objGroupList.CompareMode = vbTextCompare Set adoCommand = CreateObject("ADODB.Command") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" adoCommand.ActiveConnection = adoConnection Set objRootDSE = GetObject("LDAP://RootDSE") strDNSDomain = objRootDSE.Get("defaultNamingContext") adoCommand.Properties("Page Size") = 100 adoCommand.Properties("Timeout") = 30 adoCommand.Properties("Cache Results") = False ' Search entire domain. strBase = "<LDAP://" & strDNSDomain & ">" ' Retrieve NT name of each group. strAttributes = "sAMAccountName" ' Load group memberships for this user or computer into dictionary ' object. Call LoadGroups(objADObject) Set objRootDSE = Nothing End If If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then ' Dictionary object established, but group memberships for this ' user or computer must be added. Call LoadGroups(objADObject) End If ' Return True if this user or computer is a member of the group. IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\" _ & strGroupNTName) End Function Sub LoadGroups(ByVal objADObject) ' Subroutine to populate dictionary object with group memberships. ' objGroupList is a dictionary object, with global scope. It keeps track ' of group memberships for each user or computer separately. ADO is used ' to retrieve the name of the group corresponding to each objectSid in ' the tokenGroup array. Based on an idea by Joe Kaplan. Dim arrbytGroups, k, strFilter, adoRecordset, strGroupName, strQuery ' Add user name to dictionary object, so LoadGroups need only be ' called once for each user or computer. objGroupList.Add objADObject.sAMAccountName & "\", True ' Retrieve tokenGroups array, a calculated attribute. objADObject.GetInfoEx Array("tokenGroups"), 0 arrbytGroups = objADObject.Get("tokenGroups") ' Create a filter to search for groups with objectSid equal to each ' value in tokenGroups array. strFilter = "(|" If (TypeName(arrbytGroups) = "Byte()") Then ' tokenGroups has one entry. strFilter = strFilter & "(objectSid=" _ & OctetToHexStr(arrbytGroups) & ")" ElseIf (UBound(arrbytGroups) > -1) Then ' TokenGroups is an array of two or more objectSid's. For k = 0 To UBound(arrbytGroups) strFilter = strFilter & "(objectSid=" _ & OctetToHexStr(arrbytGroups(k)) & ")" Next Else ' tokenGroups has no objectSid's. Exit Sub End If strFilter = strFilter & ")" ' Use ADO to search for groups whose objectSid matches any of the ' tokenGroups values for this user or computer. strQuery = strBase & ";" & strFilter & ";" _ & strAttributes & ";subtree" adoCommand.CommandText = strQuery Set adoRecordset = adoCommand.Execute ' Enumerate groups and add NT name to dictionary object. Do Until adoRecordset.EOF strGroupName = adoRecordset.Fields("sAMAccountName").Value objGroupList.Add objADObject.sAMAccountName & "\" _ & strGroupName, True adoRecordset.MoveNext Loop adoRecordset.Close Set adoRecordset = Nothing End Sub Function OctetToHexStr(ByVal arrbytOctet) ' Function to convert OctetString (byte array) to Hex string, ' with bytes delimited by \ for an ADO filter. Dim k OctetToHexStr = "" For k = 1 To Lenb(arrbytOctet) OctetToHexStr = OctetToHexStr & "\" _ & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2) Next End Function -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #9 (permalink) |
| | Re: vb script - mapping drives help On Nov 18, 11:42*pm, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > Code similar to below works for me: > =============== > Option Explicit > > Dim objSysInfo, objNetwork, strUserPath, objUser > Dim adoCommand, adoConnection, strBase, strAttributes > Dim objGroupList > > Set objSysInfo = CreateObject("ADSystemInfo") > Set objNetwork = CreateObject("Wscript.Network") > > strUserPath = "LDAP://" & objSysInfo.UserName > Set objUser = GetObject(strUserPath) > > 'Removes curent mappings > On Error Resume Next > objNetwork.RemoveNetworkDrive "L:", True, True > objNetwork.RemoveNetworkDrive "J:", True, True > objNetwork.RemoveNetworkDrive "Z:", True, True > objNetwork.RemoveNetworkDrive "R:", True, True > objNetwork.RemoveNetworkDrive "N:", True, True > objNetwork.RemoveNetworkDrive "O:", True, True > objNetwork.RemoveNetworkDrive "U:", True, True > objNetwork.RemoveNetworkDrive "S:", True, True > objNetwork.RemoveNetworkDrive "M:", True, True > objNetwork.RemoveNetworkDrive "I:", True, True > objNetwork.RemoveNetworkDrive "K:", True, True > objNetwork.RemoveNetworkDrive "Z:", True, True > objNetwork.RemoveNetworkDrive "X:", True, True > objNetwork.RemoveNetworkDrive "Y:", True, True > objNetwork.RemoveNetworkDrive "Q:", True, True > On Error GoTo 0 > > If (IsMember(objUser, "MGT IT Services Group") = True) Then > * * objNetwork.MapNetworkDrive "Y:", > "\\fileserver01.tgm.domain.com\com\shares\groups\IT services", False > End If > > If (IsMember(objUser, "MGT Career Services") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Services", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", > False > End If > > If (IsMember(objUser, "MGT Career Services SAs") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Services", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", > False > End If > > If (IsMember(objUser, "MGT CIBER") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\CIBER", False > End If > > If (IsMember(objUser, "MGT Communications") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > End If > > If (IsMember(objUser, "MGT Communications Share Guest access") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > End If > > If (IsMember(objUser, "MGT Dean Suite non HR") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "U:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Assistantship", > False > * * objNetwork.MapNetworkDrive "S:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\FAcS", False > End If > > If (IsMember(objUser, "MGT Development") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Development", False > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Development\Student Share", > False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > End If > > If (IsMember(objUser, "MGT Development SAs") = True) Then > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Development\Student Share", > False > End If > > If (IsMember(objUser, "MGT Eview Users") = True) Then > * * objNetwork.MapNetworkDrive "Y:", > "\\fileserver01.tgm.domain.com\com\shares\groups\eview", False > End If > > If (IsMember(objUser, "MGT Executive Masters") = True) Then > * * objNetwork.MapNetworkDrive "I:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Programs", False > End If > > If (IsMember(objUser, "MGT Executive Programs") = True) Then > * * objNetwork.MapNetworkDrive "I:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Programs", False > End If > > If (IsMember(objUser, "MGT Explab Share participants") = True) Then > * * objNetwork.MapNetworkDrive "Z:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Explab", False > End If > > If (IsMember(objUser, "MGT Graduate Office") = True) Then > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Office", False > End If > > If (IsMember(objUser, "MGT Grad Assistant Share") = True) Then > * * objNetwork.MapNetworkDrive "U:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Assistantship", > False > End If > > If (IsMember(objUser, "MGT HR staff") = True) Then > * * objNetwork.MapNetworkDrive "X:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "Y:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Human Resources", False > * * objNetwork.MapNetworkDrive "Q:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\Pcard", False > End If > > If (IsMember(objUser, "ILE Office") = True) Then > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Institute for LE", False > End If > > If (IsMember(objUser, "ILE GRAs") = True) Then > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Institute for LE", False > End If > > If (IsMember(objUser, "MGT Tiger Share participants") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Tiger", False > End If > > If (IsMember(objUser, "MGT Undergraduate Office") = True) Then > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", > False > End If > > If (IsMember(objUser, "MGT Recruiting Share Access") = True) Then > * * objNetwork.MapNetworkDrive "Q:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Recruiting", False > End If > > If (IsMember(objUser, "MGT Faculty") = True) Then > * * objNetwork.MapNetworkDrive "S:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\FAcS", False > End If > > Function IsMember(ByVal objADObject, ByVal strGroupNTName) > * * ' Function to test for group membership. > * * ' objADObject is a user or computer object. > * * ' strGroupNTName is the NT name (sAMAccountName) of the group to test. > * * ' objGroupList is a dictionary object, with global scope. > * * ' Returns True if the user or computer is a member of the group. > * * ' Subroutine LoadGroups is called once for each different objADObject. > > * * Dim objRootDSE, strDNSDomain > > * * ' The first time IsMember is called, setup the dictionary object > * * ' and objects required for ADO. > * * If (IsEmpty(objGroupList) = True) Then > * * * * Set objGroupList = CreateObject("Scripting.Dictionary") > * * * * objGroupList.CompareMode = vbTextCompare > > * * * * Set adoCommand = CreateObject("ADODB.Command") > * * * * Set adoConnection = CreateObject("ADODB.Connection") > * * * * adoConnection.Provider = "ADsDSOObject" > * * * * adoConnection.Open "Active Directory Provider" > * * * * adoCommand.ActiveConnection = adoConnection > > * * * * Set objRootDSE = GetObject("LDAP://RootDSE") > * * * * strDNSDomain = objRootDSE.Get("defaultNamingContext") > > * * * * adoCommand.Properties("Page Size") = 100 > * * * * adoCommand.Properties("Timeout") = 30 > * * * * adoCommand.Properties("Cache Results") = False > > * * * * ' Search entire domain. > * * * * strBase = "<LDAP://" & strDNSDomain & ">" > * * * * ' Retrieve NT name of each group. > * * * * strAttributes = "sAMAccountName" > > * * * * ' Load group memberships for this user or computer into dictionary > * * * * ' object. > * * * * Call LoadGroups(objADObject) > * * * * Set objRootDSE = Nothing > * * End If > * * If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then > * * * * ' Dictionary object established, but group memberships for this > * * * * ' user or computer must be added. > * * * * Call LoadGroups(objADObject) > * * End If > * * ' Return True if this user or computer is a member of the group. > * * IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\"_ > * * * * & strGroupNTName) > End Function > > Sub LoadGroups(ByVal objADObject) > * * ' Subroutine to populate dictionary object with group memberships.. > * * ' objGroupList is a dictionary object, with global scope. It keeps track > * * ' of group memberships for each user or computer separately. ADO is used > * * ' to retrieve the name of the group corresponding to each objectSid in > * * ' the tokenGroup array. Based on an idea by Joe Kaplan. > > * * Dim arrbytGroups, k, strFilter, adoRecordset, strGroupName, strQuery > > * * ' Add user name to dictionary object, so LoadGroups need only be > * * ' called once for each user or computer. > * * objGroupList.Add objADObject.sAMAccountName & "\", True > > * * ' Retrieve tokenGroups array, a calculated attribute. > * * objADObject.GetInfoEx Array("tokenGroups"), 0 > * * arrbytGroups = objADObject.Get("tokenGroups") > > * * ' Create a filter to search for groups with objectSid equal to each > * * ' value in tokenGroups array. > * * strFilter = "(|" > * * If (TypeName(arrbytGroups) = "Byte()") Then > * * * * ' tokenGroups has one entry. > * * * * strFilter = strFilter & "(objectSid=" _ > * * * * * * & OctetToHexStr(arrbytGroups) & ")" > * * ElseIf (UBound(arrbytGroups) > -1) Then > * * * * ' TokenGroups is an array of two or more objectSid's. > * * * * For k = 0 To UBound(arrbytGroups) > * * * * * * strFilter = strFilter & "(objectSid=" _ > * * * * * * * * & OctetToHexStr(arrbytGroups(k)) & ")" > * * * * Next > * * Else > * * * * ' tokenGroups has no objectSid's. > * * * * Exit Sub > * * End If > * * strFilter = strFilter & ")" > > * * ' Use ADO to search for groups whose objectSid matches any of the > * * ' tokenGroups values for this user or computer. > * * strQuery = strBase & ";" & strFilter & ";" _ > * * * * & strAttributes & ";subtree" > * * adoCommand.CommandText = strQuery > * * Set adoRecordset = adoCommand.Execute > > * * ' Enumerate groups and add NT name to dictionary object. > * * Do Until adoRecordset.EOF > * * * * strGroupName = adoRecordset.Fields("sAMAccountName").Value > * * * * objGroupList.Add objADObject.sAMAccountName & "\" _ > * * * * * * & strGroupName, True > * * * * adoRecordset.MoveNext > * * Loop > * * adoRecordset.Close > > * * Set adoRecordset = Nothing > End Sub > > Function OctetToHexStr(ByVal arrbytOctet) > * * ' Function to convert OctetString (byte array) to Hex string, > * * ' with bytes delimited by \ for an ADO filter. > > * * Dim k > * * OctetToHexStr = "" > * * For k = 1 To Lenb(arrbytOctet) > * * * * OctetToHexStr = OctetToHexStr & "\" _ > * * * * * * & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))),2) > * * Next > End Function > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab -http://www.rlmueller.net > -- add the _ correct? |
My System Specs![]() |
| | #10 (permalink) |
| | Re: vb script - mapping drives help On Nov 18, 11:42*pm, "Richard Mueller [MVP]" <rlmueller- nos...@xxxxxx> wrote: Quote: > Code similar to below works for me: > =============== > Option Explicit > > Dim objSysInfo, objNetwork, strUserPath, objUser > Dim adoCommand, adoConnection, strBase, strAttributes > Dim objGroupList > > Set objSysInfo = CreateObject("ADSystemInfo") > Set objNetwork = CreateObject("Wscript.Network") > > strUserPath = "LDAP://" & objSysInfo.UserName > Set objUser = GetObject(strUserPath) > > 'Removes curent mappings > On Error Resume Next > objNetwork.RemoveNetworkDrive "L:", True, True > objNetwork.RemoveNetworkDrive "J:", True, True > objNetwork.RemoveNetworkDrive "Z:", True, True > objNetwork.RemoveNetworkDrive "R:", True, True > objNetwork.RemoveNetworkDrive "N:", True, True > objNetwork.RemoveNetworkDrive "O:", True, True > objNetwork.RemoveNetworkDrive "U:", True, True > objNetwork.RemoveNetworkDrive "S:", True, True > objNetwork.RemoveNetworkDrive "M:", True, True > objNetwork.RemoveNetworkDrive "I:", True, True > objNetwork.RemoveNetworkDrive "K:", True, True > objNetwork.RemoveNetworkDrive "Z:", True, True > objNetwork.RemoveNetworkDrive "X:", True, True > objNetwork.RemoveNetworkDrive "Y:", True, True > objNetwork.RemoveNetworkDrive "Q:", True, True > On Error GoTo 0 > > If (IsMember(objUser, "MGT IT Services Group") = True) Then > * * objNetwork.MapNetworkDrive "Y:", > "\\fileserver01.tgm.domain.com\com\shares\groups\IT services", False > End If > > If (IsMember(objUser, "MGT Career Services") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Services", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", > False > End If > > If (IsMember(objUser, "MGT Career Services SAs") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Services", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Career Svcs_Act", False > * * objNetwork.MapNetworkDrive "Z:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", > False > End If > > If (IsMember(objUser, "MGT CIBER") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\CIBER", False > End If > > If (IsMember(objUser, "MGT Communications") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > End If > > If (IsMember(objUser, "MGT Communications Share Guest access") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > End If > > If (IsMember(objUser, "MGT Dean Suite non HR") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "U:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Assistantship", > False > * * objNetwork.MapNetworkDrive "S:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\FAcS", False > End If > > If (IsMember(objUser, "MGT Development") = True) Then > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Development", False > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Development\Student Share", > False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > End If > > If (IsMember(objUser, "MGT Development SAs") = True) Then > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Development\Student Share", > False > End If > > If (IsMember(objUser, "MGT Eview Users") = True) Then > * * objNetwork.MapNetworkDrive "Y:", > "\\fileserver01.tgm.domain.com\com\shares\groups\eview", False > End If > > If (IsMember(objUser, "MGT Executive Masters") = True) Then > * * objNetwork.MapNetworkDrive "I:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Programs", False > End If > > If (IsMember(objUser, "MGT Executive Programs") = True) Then > * * objNetwork.MapNetworkDrive "I:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Education", False > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT_Act", False > * * objNetwork.MapNetworkDrive "K:", > "\\fileserver01.tgm.domain.com\com\shares\groups\EMSMOT", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "L:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Executive Programs", False > End If > > If (IsMember(objUser, "MGT Explab Share participants") = True) Then > * * objNetwork.MapNetworkDrive "Z:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Explab", False > End If > > If (IsMember(objUser, "MGT Graduate Office") = True) Then > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Office", False > End If > > If (IsMember(objUser, "MGT Grad Assistant Share") = True) Then > * * objNetwork.MapNetworkDrive "U:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Graduate Assistantship", > False > End If > > If (IsMember(objUser, "MGT HR staff") = True) Then > * * objNetwork.MapNetworkDrive "X:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Building Operations", False > * * objNetwork.MapNetworkDrive "N:", > "\\fileserver01.tgm.domain.com\com\shares\groups\DeanSuite", False > * * objNetwork.MapNetworkDrive "O:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting", False > * * objNetwork.MapNetworkDrive "Y:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Communications", False > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Human Resources", False > * * objNetwork.MapNetworkDrive "Q:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\Pcard", False > End If > > If (IsMember(objUser, "ILE Office") = True) Then > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Institute for LE", False > End If > > If (IsMember(objUser, "ILE GRAs") = True) Then > * * objNetwork.MapNetworkDrive "J:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Institute for LE", False > End If > > If (IsMember(objUser, "MGT Tiger Share participants") = True) Then > * * objNetwork.MapNetworkDrive "R:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Tiger", False > End If > > If (IsMember(objUser, "MGT Undergraduate Office") = True) Then > * * objNetwork.MapNetworkDrive "M:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Undergraduate Office", > False > End If > > If (IsMember(objUser, "MGT Recruiting Share Access") = True) Then > * * objNetwork.MapNetworkDrive "Q:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Recruiting", False > End If > > If (IsMember(objUser, "MGT Faculty") = True) Then > * * objNetwork.MapNetworkDrive "S:", > "\\fileserver01.tgm.domain.com\com\shares\groups\Accounting\FAcS", False > End If > > Function IsMember(ByVal objADObject, ByVal strGroupNTName) > * * ' Function to test for group membership. > * * ' objADObject is a user or computer object. > * * ' strGroupNTName is the NT name (sAMAccountName) of the group to test. > * * ' objGroupList is a dictionary object, with global scope. > * * ' Returns True if the user or computer is a member of the group. > * * ' Subroutine LoadGroups is called once for each different objADObject. > > * * Dim objRootDSE, strDNSDomain > > * * ' The first time IsMember is called, setup the dictionary object > * * ' and objects required for ADO. > * * If (IsEmpty(objGroupList) = True) Then > * * * * Set objGroupList = CreateObject("Scripting.Dictionary") > * * * * objGroupList.CompareMode = vbTextCompare > > * * * * Set adoCommand = CreateObject("ADODB.Command") > * * * * Set adoConnection = CreateObject("ADODB.Connection") > * * * * adoConnection.Provider = "ADsDSOObject" > * * * * adoConnection.Open "Active Directory Provider" > * * * * adoCommand.ActiveConnection = adoConnection > > * * * * Set objRootDSE = GetObject("LDAP://RootDSE") > * * * * strDNSDomain = objRootDSE.Get("defaultNamingContext") > > * * * * adoCommand.Properties("Page Size") = 100 > * * * * adoCommand.Properties("Timeout") = 30 > * * * * adoCommand.Properties("Cache Results") = False > > * * * * ' Search entire domain. > * * * * strBase = "<LDAP://" & strDNSDomain & ">" > * * * * ' Retrieve NT name of each group. > * * * * strAttributes = "sAMAccountName" > > * * * * ' Load group memberships for this user or computer into dictionary > * * * * ' object. > * * * * Call LoadGroups(objADObject) > * * * * Set objRootDSE = Nothing > * * End If > * * If (objGroupList.Exists(objADObject.sAMAccountName & "\") = False) Then > * * * * ' Dictionary object established, but group memberships for this > * * * * ' user or computer must be added. > * * * * Call LoadGroups(objADObject) > * * End If > * * ' Return True if this user or computer is a member of the group. > * * IsMember = objGroupList.Exists(objADObject.sAMAccountName & "\"_ > * * * * & strGroupNTName) > End Function > > Sub LoadGroups(ByVal objADObject) > * * ' Subroutine to populate dictionary object with group > ... > > read more » around lines) But one time upon logging on, I got a network name not found. I have the Group Policy set to wait for the network before starting logon scripts, but what would cause the computer to not recognize the path, but upon logging off, and back on again, no problems. It is as if the script is run "Sometimes" before DNS is activated. Does that sound plausible? |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Script Mapping all Drives | VB Script | |||
| Mapping network drives - JSF | Vista General | |||
| mapping drives | PowerShell | |||
| Mapping non Domain drives | Vista networking & sharing | |||
| Vista and Mapping Drives via script | Vista General | |||