Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for mapped network drives

Status
Not open for further replies.

SysAdmin3000

Technical User
Aug 15, 2006
15
US
I have created a login script for my 2k3 environment. After reviewing the FAQ, great work btw, I added disconnect network drives.

Right now when I run the script and it gets the the disconnect network drives section an error is posted stating 'This network connection does not exist.' Which is correct as the drives are not currently mapped.

I would like to have the script check for any mapped drives and if they exist then disconnect them. If they do not exist then move on.

I am not sure how to do this. I will keep researching other sources as well.

Any advice is appreciated.

 
Add On Error Resume Next to the top of your script.

MrMovie also posted an FAQ that first checks if a drive is mapped and then disconnects. I respectfully think this is overkill as the On Error Resume Next is sufficient to allow the script to continue processing and move on to the next command.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Thanks Mark.

I had On Error Resume Next in the code. Initially I thought that it would be better to check for the drives then delete if they exist. After reading your post I asked myself, why?

If the code debugs ok and the script runs why add another layer of complication?

Thanks for replying and letting me bounce this idea off of someone.
 
Happy to help. I am of the same mind. Why do I care if the drive wasn't there? It will still get remapped when I want it to later.

Note too that there are times when you need to use On Error Resume Next. For example if you try to read a registry key and it does not exist, you need to use On Error Resume Next to be able to move on to error trapping to create the key if you need to etc.

As I recall the thread that inspired MrMovie to write his FAQ, he indicated that there was a slight performance increase by first checking. But to me the added complexity for a minor performance increase doesn't justify the effort.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
>If the code debugs ok and the script runs why add another layer of complication?
It is good to ask yourself why? and it is good too to ask yourself adding "on error resume next" at the top of your script the other question: why not? As you have plenty of opinions, I'll leave it to you to answer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top