Link to home
Create AccountLog in
Avatar of ddantes
ddantesFlag for United States of America

asked on

Automating a step in a batch file.

Running Windows 7 32-bit, I have a batch file in the Startup folder, which maps a network drive (V:) to Windows Explorer.  This is necessary, because the drive is a shared folder within a N.A.S.  Here is the batch file code:

net use V: \\V:\Data
net use V: \\DiskStation3\Data

Sometimes, after rebooting, the batch file won't complete without user interaction.  A question appears in the command window:  "V: has a remembered connection to \\Diskstation-3\Data.  Do you want to override the remembered connection?"

The answer is "no", and I'm wondering if there is code which can be added to the batch file to automate that response, if the question appears?

Avatar of arnold
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of ddantes


Thank you.
When I do a "net use" command in a .CMD file to create a mapping, I usually precede it with a command to delete the map if it already exists.  In your case:
net use v: /delete
It will generate an error message if V: isn't already mapped, but it will continue executing.
Avatar of ddantes


Thank you, but I'm hesitant to add that feature.  The mapping would require credentials, once the map is deleted.  Unless that code is essential, I'd like to use the batch file as it is. 
Removing the errornous line won't change the prompt if the drive is already mapped. You can use
net use Y: 2>nul >nul || net use Y: \\DiskStation3\Data 

Open in new window

to only map if there is no drive Y: yet.
Avatar of ddantes


Thank you, I will make that code adjustment!