chemdry
asked on
Mapping Network Drives through a login script
I need to map some network drives using a login script. We are on a windows 2000 server and are using Group policies and active directory. This is worth 500 and I need the following information
1. I need to map the same drives to everyone's computer. The drives that need mapping are I: through Y: I need a vb script that will first check to see if the correct mapping is there, if not delete it (only I: through Y: Leave the others alone) and map the correct path for the drive. It would be ok to leave the mappings there when logging off so they are already mapped when they log back in.
2. Not all of the users can access all of the drives, but I would still like them mapped so they know they exist and can ask for permission to access it if they feel they have a reason to as well has having the mappings the same company wide. If they don't have authority to access a mapped folder on the network, will it still map it or will it fail when the script runs?
3. Some printers have card readers and are taking up some drives like p: and q: what will happen in this settings?
4. Are there any Group Policies that should be set to make sure that the script runs first before other programs start that might use data on the mapped drives?? Any info in this area would be great
Thanks,
Aaron
1. I need to map the same drives to everyone's computer. The drives that need mapping are I: through Y: I need a vb script that will first check to see if the correct mapping is there, if not delete it (only I: through Y: Leave the others alone) and map the correct path for the drive. It would be ok to leave the mappings there when logging off so they are already mapped when they log back in.
2. Not all of the users can access all of the drives, but I would still like them mapped so they know they exist and can ask for permission to access it if they feel they have a reason to as well has having the mappings the same company wide. If they don't have authority to access a mapped folder on the network, will it still map it or will it fail when the script runs?
3. Some printers have card readers and are taking up some drives like p: and q: what will happen in this settings?
4. Are there any Group Policies that should be set to make sure that the script runs first before other programs start that might use data on the mapped drives?? Any info in this area would be great
Thanks,
Aaron
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Very true... mine is only meant to demonstrate what can be done and how it might be done rather than being completely functional and efficient, especially since it repeats itself :)
ASKER
Great feedback!
I just have a couple follow up questions and then I'll close this by sharing the points among the three of you since each contributed some great answers.
Leew - If I understand you right about if someone doesn't have permissions to access a folder, you can't map it. I tested the following. If there is a shared folder, and on the shared tab under properties only the accounting group has permission to access the share, I found that others not in the accounting group CAN map the drive by manually mapping throught tools map network drive, but can't access it when they click the mapping. Do you mean that the everyone group needs to be listed in this shared permissions, but not in security tabe under the properties box so when the script runs it can map it? I don't quite understand your point.
Chris-Dent and sr75 - since I only want to map I: through Y: and leave any other mappings alone that they might have in say H: (I don't know vbscripting but do know c++, perl, php really well) it looks like to me that the following code will delete all of the mappings including H: Is this true or will the following code only remove I: through Y mappings??
for each item in Drives
if right(item,1) = ":" then
Net.RemoveNetworkDrive item
end if
next
Also Chris-Dent - I liked your code on the printer mappings, if the user already has that printer mapped, and you map it again, will it just over write the previous or make a duplicate printer mapping?
If anyone knows any good books on vb scripting I would love some suggestions. The reason why I wanted the code in vb was because I already have a auditing vb script that I would combine with this mapping one. I assume I would just place this auditing code after the mapping and it will run fine (right?)
I just have a couple follow up questions and then I'll close this by sharing the points among the three of you since each contributed some great answers.
Leew - If I understand you right about if someone doesn't have permissions to access a folder, you can't map it. I tested the following. If there is a shared folder, and on the shared tab under properties only the accounting group has permission to access the share, I found that others not in the accounting group CAN map the drive by manually mapping throught tools map network drive, but can't access it when they click the mapping. Do you mean that the everyone group needs to be listed in this shared permissions, but not in security tabe under the properties box so when the script runs it can map it? I don't quite understand your point.
Chris-Dent and sr75 - since I only want to map I: through Y: and leave any other mappings alone that they might have in say H: (I don't know vbscripting but do know c++, perl, php really well) it looks like to me that the following code will delete all of the mappings including H: Is this true or will the following code only remove I: through Y mappings??
for each item in Drives
if right(item,1) = ":" then
Net.RemoveNetworkDrive item
end if
next
Also Chris-Dent - I liked your code on the printer mappings, if the user already has that printer mapped, and you map it again, will it just over write the previous or make a duplicate printer mapping?
If anyone knows any good books on vb scripting I would love some suggestions. The reason why I wanted the code in vb was because I already have a auditing vb script that I would combine with this mapping one. I assume I would just place this auditing code after the mapping and it will run fine (right?)
I have you both beat, its like name that tune, I can write this script in 7 lines of code Chuck.
This script will go through all drives mapped and as it finds one it will delete it as long as it is not in use. Then list out the drive mappings you want to have.
************************** ********** ********** ********** **
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set oDrives = WshNetwork.EnumNetworkDriv es
WScript.Echo "Network drive mappings:"
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
WshNetwork.RemoveNetworkDr ive(oDrive s.Item(i))
Next
WshNetwork.MapNetworkDrive "E:", "\\Server\Public"
WshNetwork.MapNetworkDrive "F:", "\\Server\Public"
WshNetwork.MapNetworkDrive "G:", "\\Server\Public"
************************** ********** ********** ********** **
This script will go through all drives mapped and as it finds one it will delete it as long as it is not in use. Then list out the drive mappings you want to have.
**************************
Set WshNetwork = WScript.CreateObject("WScr
Set oDrives = WshNetwork.EnumNetworkDriv
WScript.Echo "Network drive mappings:"
For i = 0 to oDrives.Count - 1 Step 2
WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
WshNetwork.RemoveNetworkDr
Next
WshNetwork.MapNetworkDrive
WshNetwork.MapNetworkDrive
WshNetwork.MapNetworkDrive
**************************
If H: is your user's home folder in AD, it would leave it. If it is a mapped drive, it would delete it. Well that is the way it works on my network. (My H:\ is the user's home folder).
Yes, the home drive may be an issue for the script, especialy if you are using folder redirection to your home drive. You can add the "On Error Resume Next" to the top of the script and it will continue through all the drives even though it might not kill the Home drive if it is setup in this manner. You would have to kill the session from the server first and then you would be able to remove the drive via script.
If you must you can edit this line:
if right(item,1) = ":" then
To this :
if item <> "H:" then
That would delete all but the H: drive.
if right(item,1) = ":" then
To this :
if item <> "H:" then
That would delete all but the H: drive.
Also, if you have more drives to delete you could remove this from my script
set Drives = Net.EnumNetworkDrives
for each item in Drives
if right(item,1) = ":" then
Net.RemoveNetworkDrive item
end if
next
and edit each:
If InStr(strGroup, "User") then
Drv = "I:"
Net.MapNetworkDrive Drv, "\\Server\Share"
End If
to say:
If InStr(strGroup, "User") then
Drv = "I:"
Net.RemoveNetworkDrive Drv
Net.MapNetworkDrive Drv, "\\Server\Share"
End If
That would delete it then recreate it
set Drives = Net.EnumNetworkDrives
for each item in Drives
if right(item,1) = ":" then
Net.RemoveNetworkDrive item
end if
next
and edit each:
If InStr(strGroup, "User") then
Drv = "I:"
Net.MapNetworkDrive Drv, "\\Server\Share"
End If
to say:
If InStr(strGroup, "User") then
Drv = "I:"
Net.RemoveNetworkDrive Drv
Net.MapNetworkDrive Drv, "\\Server\Share"
End If
That would delete it then recreate it
Hi Aaron,
I think sr75 covered deleting the drive mapping in plenty of detail?
The scripted printer mapping will overwrite any current mapping to that printer. It won't create duplicate connections to the same printer.
Chris
Oops, there's a typo in the IsMember Function:
For Each objGroup In objUser.Groups
If objGroup.Name = strGroupName Then
bolIsMember = TRUE
Exit For
End If
Next
Should be:
For Each objGroup In objUser.Groups
If objGroup.Name = strGroupName Then
booIsMember = TRUE
Exit For
End If
Next