mac_shinobi Posted March 2, 2007 Posted March 2, 2007 I have this script , I have tried to alter the script so that strusername = objNetwork.UserName and at the minute I have it so that strusername = objNetwork.ComputerName. I have made it a startup script in gpo and have applied this to an ou that only my machine is in and made it apply to everyone that is in the Machines OU, my machine is in there, I have done a gpupdate on the server and a gpupdate /force on my machine and restarted and logged back in and no success with mapping the drives. Here is the script : Option Explicit Dim StrUserName, objNetwork, user, pass, strprofile const marketing = "\\server\Marketing" const FDrive = "\\server\company" const creative = "\\server\creativeserver" const mitn = "\\server\MITN_shared" Set objNetwork = CreateObject("Wscript.Network") strUserName = objNetwork.ComputerName Select Case strUserName Case "Comp1": Call check("M:",marketing) Call check("F:",FDrive) Call cs("S:",creative,false,"user","pass") Call check("Z:",mitn) Case "Comp2": Call check("M:",marketing) Call check("F:",FDrive) Call cs("S:",creative,false,"user","pass") Call check("Z:",mitn) Case "MyComp": Call check("K:",FDrive) Call cs("S:",creative,false,"user","pass") Call check("Z:",mitn) Case Else: Call check("F:",FDrive) Call cs("S:",creative,false,"user","pass") Call check("Z:",mitn) End Select Public Function check(ByRef strDriveLetter, ByRef strRemotePath) Set objNetwork = CreateObject("Wscript.Network") Dim CheckDrive, AlreadyConnected, intDrive Set CheckDrive = objNetwork.EnumNetworkDrives() ' This section deals with a For ... Next loop ' See how it compares the enumerated drive letters ' with strDriveLetter On Error Resume Next AlreadyConnected = False For intDrive = 0 To CheckDrive.Count - 1 Step 2 If CheckDrive.Item(intDrive) = strDriveLetter Then AlreadyConnected = True End If Next ' This section uses the If = then, else logic ' This tests to see if the Drive is already mapped. ' If yes then disconnects Select Case AlreadyConnected Case "True": objNetwork.RemoveNetworkDrive strDriveLetter objNetwork.MapNetworkDrive strDriveLetter, strRemotePath Case "False": objNetwork.MapNetworkDrive strDriveLetter, strRemotePath End Select End Function Public Function cs(ByRef strDriveLetter, ByRef strRemotePath, ByRef prof, ByRef User, ByRef Pass) Set objNetwork = CreateObject("Wscript.Network") Dim CheckDrive, AlreadyConnected, intDrive Set CheckDrive = objNetwork.EnumNetworkDrives() ' This section deals with a For ... Next loop ' See how it compares the enumerated drive letters ' with strDriveLetter On Error Resume Next AlreadyConnected = False For intDrive = 0 To CheckDrive.Count - 1 Step 2 If CheckDrive.Item(intDrive) = strDriveLetter Then AlreadyConnected = True End If Next ' This section uses the If = then, else logic ' This tests to see if the Drive is already mapped. ' If yes then disconnects Select Case AlreadyConnected Case "True": objNetwork.RemoveNetworkDrive strDriveLetter objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass Case "False": objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, strprofile, user, pass End Select End Function Can someone shed some light on what I am doing wrong or what needs to be fixed so that I can get this to work correctly, do I need to do a wscript.sleep for 15 seconds before it runs so it gives the machine a chance to load or what exactly ? Thanks
timbo343 Posted March 2, 2007 Posted March 2, 2007 usually it runs straight away, mine are in the netlogon folder. this works fine, but am soon wanting it to be user specific too... ' Setting the parameters On error resume next Set wshnetwork = CreateObject("WScript.Network") Set ADSysInfo = CreateObject("ADSystemInfo") Set CurrentUser = GetObject("LDAP://" & ADSysInfo.Username) Set Drives = wshnetwork.EnumNetworkDrives set fso = CreateObject("Scripting.FileSystemObject") strGroups = LCase(CurrentUser.MemberOf) strGroups = LCase(Join(CurrentUser.MemberOf)) ' Setting the groups of departments with the member of settings in AD Const Staff = "cn=staff" Const Maths = "cn=mathematics" Const PowerStaff = "cn=powerstaff" Const ITTeach = "cn=information technology" Const ITAdmin = "cn=admin" Const DesignTechnology = "cn=design technology" Const H2L = "cn=special needs" Const Careers = "cn=careers" ' admin settings Const AdminStaff = "cn=generaladmin" Const OfficeGroup = "cn=Office Group" ' All general users ' Delete all network drives If right(item,1) = ":" then wshnetwork.removenetworkdrive item end if ' Adding the Drives for the specific groups 'Staff group If Instr(strGroups,staff) Then On Error Resume Next wshnetwork.RemoveNetworkDrive "p:" wshnetwork.RemoveNetworkDrive "s:" wshnetwork.RemoveNetworkDrive "v:" wshnetwork.RemoveNetworkDrive "q:" wshNetwork.MapNetworkDrive "p:","\\hades\upublic" wshNetwork.MapNetworkDrive "s:","\\hades\business" wshNetwork.MapNetworkDrive "v:","\\hades\uapps" wshnetwork.mapnetworkdrive "q:","\\seth\users\home\administration" 'ITAdmin Group If Instr(strGroups,ITAdmin) Then wshnetwork.RemoveNetworkDrive "n:" wshnetwork.RemoveNetworkDrive "w:" wshnetwork.RemovenetworkDrive "y:" wshnetwork.RemoveNetworkDrive "x:" wshNetwork.MapNetworkDrive "n:","\\chaos\notes" wshNetwork.MapNetworkDrive "w:","\\hades\apps" wshnetwork.MapnetworkDrive "y:","\\hades\profiles" wshnetwork.mapnetworkdrive "x:","\\seth\users\home" End If 'ITAdmin ' Powerstaff group If Instr(strGroups,powerstaff) Then wshNetwork.MapNetworkDrive "x:","\\Seth\users\home" End If 'Powerstaff ' ITTeach Group If Instr(strGroups,itteach) Then wshnetwork.RemoveNetworkDrive "o:" wshNetwork.MapNetworkDrive "o:","\\seth\ITStaff" End If 'ITTeach ' Maths Group If Instr(strGroups,Maths) Then wshNetwork.MapNetworkDrive "m:","\\seth\users\home\MathsStaff" End If 'Maths ' DesignTechnology Group If Instr(strGroups,designtechnology) Then wshnetwork.mapnetworkdrive "m:","\\seth\users\home\destech" End If 'designtechnology ' H2L Group If Instr(strGroups,H2L) then wshnetwork.mapnetworkdrive "m:","\\seth\users\home\h2lstaff" End if 'H2L ' Careers Group If Instr(strGroups,Careers) then wshnetwork.mapnetworkdrive "t","\\seth\user\wxpnet" End if 'Careers ' AdminStaff Group If Instr(strGroups,adminstaff) then wshnetwork.mapnetworkdrive "f:","\\server\apps" wshnetwork.mapnetworkdrive "L:","\\server\public" wshnetwork.mapnetworkdrive "q:","\\seth\users\home\administration" End if 'adminstaff ' OfficeGroup Group If Instr(strGroups,Officegroup) then wshnetwork.mapnetworkdrive "k:","\\server\common" End if 'officegroup End If 'Staff
mac_shinobi Posted March 2, 2007 Author Posted March 2, 2007 now it adds all my network drives but it tells me they are all disconnected and they still show up in my computer but I cant disconnect them , when I try to disconnect them it just tells me that there are no network drives to disconnect :-S ok what do I do to fix that ?
mac_shinobi Posted March 2, 2007 Author Posted March 2, 2007 Network drives screenshot of it saying they are disconnected yet they still work, why is it telling me they are disconnected ?
timbo343 Posted March 2, 2007 Posted March 2, 2007 what are you trying to do, just map network drives for individuals or user groups?
mac_shinobi Posted March 2, 2007 Author Posted March 2, 2007 What I did was put the users I want the mapped drives into an ou and then made it a logon script because there are several mappings that are available and not all the users have all of them , they have specific ones mapped to them dependant upon there needs / requirements. So the vbscript does all that. That way I dont get the disconnected text in front of the mapping as per the screen shot. Will be a work in progress because there is more to do to the script to get it how I want but it works as in it maps the relevant drives and there is no disconnected message in front of the mapping anymore.
mac_shinobi Posted March 8, 2007 Author Posted March 8, 2007 ok now I am getting the error message that the drives could not be re connected, yet if you click on the yellow prompt in the system tray or open up my computer the drives that I want mapped are mapped and connected and nothings wrong with it that I can tell. Aside from it giving me the error message, how do I get rid of that or why is it telling me that they could not be re connected when they are connected ?
djm968 Posted March 8, 2007 Posted March 8, 2007 Do you have any shortcuts on the desktop that link to files on the network drives? If so, change the shortcuts to point to the UNC path and not the mapped drive letter.
mac_shinobi Posted March 8, 2007 Author Posted March 8, 2007 no, only things I have on my desktop are actual files or folders that aren't linked to any unc path or any mapped drives. I have assigned the script via a logon script in the user config of GPO on the OU as I clicked on link and create a gpo on the main ou for each group ie marketing has one gpo that has a vbscript assigned as a logon script and internal OU has another one etc. I thought it was maybe that I needed to use wscript.sleep 5000 or make it wait longer to give it time to disconnect the mapped drives before hand but that didnt work. I also tried enabling slow network connection on the system --> logon of gpo as well as enabling synchronised scripts. As per this google article ( aside from the fact that I did it using group policy for the OU and not on the local machine ) 1. Click Start, and click Run. 2. Type "gpedit.msc" in the text box, and click OK. 3. Locate the [Computer Configuration\Administrative Templates\System\Logon\Always wait for the network at computer startup and logon], and select "Enabled", and click OK. 4. Locate the [user Configuration\Administrative Templates\System\Scripts\Run logon scripts synchronously], and select "Enabled", and click OK. 5. Reboot computer to test this issue again. found here : http://groups.google.co.uk/group/microsoft.public.windows.server.sbs/browse_thread/thread/407d4b54f637e7fa/50c35b840d00cb2e?lnk=st&q=could+not+reconnect+all+network+drives&rnum=1&hl=en#50c35b840d00cb2e
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now