Link to home
Start Free TrialLog in
Avatar of sasllc
sasllcFlag for United States of America

asked on

How to refresh a network share from the command prompt

Our typical customer has a few XP computers that share files among each other via simple file sharing.  For example, Computer A may map to the C:\ drive of Computer B and call it drive X:.  But now and then Computer B may temporarily "lose" the connection to drive X:, and of course an easy way to refresh the connection is to go to My Computer and double click the X: drive, and then all the folders appear.

My question is how to do this "refreshing" from a command prompt.  While running a batch file using Xcopy, I need to be sure I have a good connection to drive X: so that the copy does not fail.  The only way I know of is to do this each time in the batch file:

NET USE X: /DELETE
NET USE X: \\BOB\C

But I don't know for sure if that's reliable, and I hate to have write out all the NET USE connections in the batch file and have them run each time.  Is there a better way to do this?  Some command I can run that effectively does the same thing as double-clicking that icon in My Computer?  TIA

ASKER CERTIFIED SOLUTION
Avatar of garethh86
garethh86
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sasllc

ASKER

I do understand that XP should not lose it's mappings if it's done with a /persistent:yes option, or better yet done from within Windows, but the problem is that is does do so now and then...for reasons that have never been obvious to me.  Since this Xcopy batch file needs to run unattended, I've got to be SURE that all the connections are good, which is why I need a way to "refresh" them each time it runs at night, just in case any of the mappings have failed.  And, if I use a NET USE command, apparently I need to do a /delete each time before I re-establish the drive mapping, because otherwise I will get an error saying that drive letter is already in use (or something like that).

But bottom line, it looks like you are saying that doing a NET USE each time IS the best way, right?  Or, is MAKESHARE somehow better?  I'm not familiar with MAKESHARE; it is just another way to do a NET USE, or what does it actually do?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, MAKESHARE was just a variable name, you can make that anything you want. This just saves you typing out the net use command many times for example:

SET TEST=echo Hello
%TEST%

would return 'Hello' to the screen.

As ebjers says net use will re-establish the connection if dropped so just put the net use command in the batch with the xcopy functions and you shouldn't have any problems. You do not have to delete then re-create.

Good examples on Batch file commands can be found here:

http://www.computerhope.com/batch.htm

Good luck!