I've been working to clean up a messy Active Directory as well as a network file system in the same state and I understand the concept of mapping users network drives and currently use a combination of batch and vbs files to do so. However, I need to start fresh and was wondering if there was any way to detect and delete the users shortcuts on their desktop associated with the previous network drives. (Yes - I understand how to delete all of the network drives, but: How do I detect and delete the shortcuts on the desktop associated with them?)
I've already written and custom tailored my own scripts to map drives and place shortcuts. I just need to get rid of any old shortcuts. I can't afford to delete all of the .ink files on the desktop, either. Only any associated with preexisting network drives.
I'm working in an XP / Server 2003 client/server environment.
Another question: If a script runs every time a user logs on through the domain and adds the same network shares over and over again without first deleting them, (even though it would be the same script every time) would it / does it - do any harm? <- I didn't research this one a whole lot yet because i've been crawling through Google and took a peak see through Stack to try and find a solution for the first question/issue.
Any help / advice would be greatly appreciated. Thanks!
Let's say there was before in logon batch
and the users created shortcuts to files / directories on this share on their desktop or in a subdirectory of the desktop.
A shortcut file contains always both - the path to the file with drive letter as well as the UNC path with server and share names.
A simple batch file to find in desktop directory and all its subdirectories *.lnk files containing
\\OldServer\OldShare
and delete all found shortcut files isFor details about
/I /M /S
run in a command prompt windowfindstr /?
As it can be seen each backslash in the find string must be escaped with one more backslash.
It is also possible to search for
"Z:\\"
instead of"\\\\OldServer\\OldShare"
But be careful with deletion of a *.lnk file just based on drive letter because users could have mapped a different share to this drive letter. Those users would not be happy if their shortcuts are deleted, too.
The batch file could ask the user for confirmation before deleting every found shortcut containing the drive letter of not anymore existing drive:
It is no problem if a network drive mapping using a command like
is done in logon batch file on every logon. An error message is output by
net use
if drive letter Z: is used already, for example if the network drive mapping was done persistent and the user started the computer first without a network connection, then plugged-in the network cable and next after a few seconds entered user name and password to logon to Windows and on domain server of the company.It is possible to use
to first delete an already existing network drive mapping before mapping the share to drive letter Z:. I do not recommend to use wildcard
*
instead ofZ:
as that would delete also all network drive mappings created by the user.For computers not only used in the company network, it is often better to make the drive mapping not persistent by using
Now Windows does not save in Windows registry that
\\MyServer\MyShare
should be mapped automatically toZ:
and therefore the network drive mapping exists only for current user session. The network drive mapping is removed automatically once Windows is restarted or the user logs off.