I have a app which requires a connection to a remote w开发者_StackOverflow社区indows. What I have done is to use mapped drive to build the connection on Windows startup menu. The partial codes look like this:
@IF NOT EXIST \\remotePC\sharedFolder NET USE * \\remotePC\sharedFolder /USER:user1 pwd /PERSISTENT:YES
The net use map works fine. The mapped drive will be one from available network drive letters. In my app, then UNC name is used instead(\remotePC\sharedFolder).
The issue(not sure it is an issue) is that after several reboots, I can see a list of disconnected drivers from File Explorer:
I am not sure all the letters would be used up if I reboot my PC many times? I would like to clean up all the disconnected network drives. Can I do it from the batch script? I tried to use net use again for a disconnected drive, it deletes OK first time, but it stays in File Explorer.
NET USE T: /DELETE
Notes: I am not sure the usage of option /PERSISTENT:YES. I think it should reconnect the network drive after log in or reboot. It does not happen. That's why I added my scripts to Start up menu. I also realize that my other file explorer tools also display the disconnected network drives. Each time I reboot, one more disconnected network drive appears. It seems that the disconnected network drives does exists in Windows. Is there any way in scripts to find them and clean them?
Update: I run my test up to 10 times and now I get to the stage that no more letter available for network drive mapping. Here is the snap-shot of my network drive status by using Total Commander:
If I right click on those disconnected network drives, I can disconnect them. There must be a way to make those disconnected ones back to available. However, it would not be released by the use net /delete command:
NET USE X: /DELETE
The disconnected ones are caused by reboot or logout. It seems that I have no control over them since 1) I use dynamic mapping, and 2)no place to plugin my script before reboot or logout. One way I can think about is to do reconnect by using the following command (simplified one):
IF NOT EXIST Y:\ NET USE \\remotePC\Shared...
where Y: may be from a loop. Above is a simplified one. I tried it from cmd and it works.
However before I put it with loop to my batch script, I prefer to clean up all the disconnected ones. That comes to another way: to add some scripts to my batch in start up to do the clean up. If there is any script codes or tools available so that I can use in my batch script to make disconnected ones back to available?
I think I figure out a solution. In my mapping script, instead of yes to persistent, I should use no:
NET USE * \\remotePC\sharedFolder /USER:user1 pwd /PERSISTENT:NO
this option tells Windows do not keep this network drive persistent for reconnection(you could click on broken one from File Explorer to get it back). As a result, when a user login again after logout or reboot, the network drive will not be in the list of disconnected ones. I'll not run into the issue of running out of network drive letters.
Actually my work colleague helped me with this solution, and I would like to share it with people who have interest in this issue.
精彩评论