Link to home
Create AccountLog in
Avatar of jaramart
jaramart

asked on

Network Drive Scripts

Howdy i am just wondering if anyone has a script either batch or VBS that connects networked Mapped Drives at loggon. However i want it to be able to Remove the drive letter assigned to removable drives ie. USB or card Readers. so that that mappings are uniformed accross the site.

thanks
Avatar of cyberkiwi
cyberkiwi
Flag of New Zealand image

For example

rem remove some drives first - allow it to fail, we don't care
net use T: /delete
net use X: /delete

rem add new drives
net use T: \\netserver\share

Open in new window

You can also remove all mapped drives without error
net use * /delete

Open in new window

Avatar of jaramart
jaramart

ASKER

Can you give it parameters ie. remove all except c:
The net use command will not map drives or remove local drive letters that have already been assigned by the local machine.
You'll need an application to eject local devices - I have used the one described in this link with success: http://www.howtogeek.com/howto/windows-vista/create-a-shortcut-or-hotkey-to-immediately-eject-a-specific-usb-drive/

You can use the FileSystemObject to loop through all the drives and check if each 1) conflicts with a network mapping and 2) it's drive type is removable, and if so run the command in the link above.

http://msdn.microsoft.com/en-us/library/hww8txat(v=VS.85).aspx
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Can you give it parameters ie. remove all except c:

Can't think of a way except the elaborate

net use D: /delete
net use E: /delete
etc
Yes, you can just loop through the Drives and if DriveLetter <> "C:" then delete it.

However, 1) you can't use "net use /delete" to remove USB drives, and 2) I don't see any sense in removing drive letters unless they conflict with a network mapping.