Batch file to reconnect home NAS

B

bwawawa

I bought a Airlink101 Office NAS ANAS350 with 500GB Seagate SATA drive
in it for my home network to store files files like MP3's, pictures
and to back up all my computers. I don't have domain server at my
home. Everytime I reboot the NAS need me to remap the drives and
sometimes it doesn't even take my password that I'd have to
'disconnect' all mapped drive and remap. It's kinda annoying. I
started creating this batch file piece by piece based on someone else
batch file to connect to my private folder as p: drive, s: drive as
public drive and t: drive as the 160GB Seagate USB external drive.

@echo off
cls
if exist p: goto drivefound2 else
goto end
:drivefound2
net use p: /del
:end

pause

if exist s: goto drivefound3
goto end
:drivefound3
net use s: /del
:end

pause

if exist t: goto drivefound4
goto end
:drivefound4
net use t: /del
:end

pause

net use p: \\airnas\default mypassword /user:airnas\default rem
default as private folder
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c

:END
echo DONE!

Is there anything more it can look better than this?
 
T

Todd Vargo

I bought a Airlink101 Office NAS ANAS350 with 500GB Seagate SATA drive
in it for my home network to store files files like MP3's, pictures
and to back up all my computers. I don't have domain server at my
home. Everytime I reboot the NAS need me to remap the drives and
sometimes it doesn't even take my password that I'd have to
'disconnect' all mapped drive and remap. It's kinda annoying. I
started creating this batch file piece by piece based on someone else
batch file to connect to my private folder as p: drive, s: drive as
public drive and t: drive as the 160GB Seagate USB external drive.

@echo off
cls
if exist p: goto drivefound2 else
goto end
:drivefound2
net use p: /del
:end

pause

if exist s: goto drivefound3
goto end
:drivefound3
net use s: /del
:end

pause

if exist t: goto drivefound4
goto end
:drivefound4
net use t: /del
:end

pause

net use p: \\airnas\default mypassword /user:airnas\default rem
default as private folder
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c

:END
echo DONE!

Is there anything more it can look better than this?

First of all, you can not have more than one label named "end". Well you
could, but only the first one will be seen by the GOTO statement. Second,
your 3 "IF EXIST" conditions only skip the GOTO statement that follows them.
If you reconstruct as "IF NOT EXIST" conditions, you could eliminate one
GOTO statement and one label each. The following code has a cleaner
appearance and IMO, is easier to follow program flow. Do you agree?

@echo off
cls
if not exist p: goto skip_p
net use p: /del
:skip_p

if not exist s: goto skip_s
net use s: /del
:skip_s

if not exist t: goto skip_t
net use t: /del
:skip_t

net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!
 
F

foxidrive

I bought a Airlink101 Office NAS ANAS350 with 500GB Seagate SATA drive
in it for my home network to store files files like MP3's, pictures
and to back up all my computers. I don't have domain server at my
home. Everytime I reboot the NAS need me to remap the drives and
sometimes it doesn't even take my password that I'd have to
'disconnect' all mapped drive and remap. It's kinda annoying. I
started creating this batch file piece by piece based on someone else
batch file to connect to my private folder as p: drive, s: drive as
public drive and t: drive as the 160GB Seagate USB external drive.


@echo off
cls
if exist p: net use p: /del
if exist s: net use s: /del
if exist t: net use t: /del
net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!
 
A

Al Dunbar

Todd Vargo said:
First of all, you can not have more than one label named "end". Well you
could, but only the first one will be seen by the GOTO statement. Second,
your 3 "IF EXIST" conditions only skip the GOTO statement that follows
them.
If you reconstruct as "IF NOT EXIST" conditions, you could eliminate one
GOTO statement and one label each. The following code has a cleaner
appearance and IMO, is easier to follow program flow. Do you agree?

@echo off
cls
if not exist p: goto skip_p
net use p: /del
:skip_p

if not exist s: goto skip_s
net use s: /del
:skip_s

if not exist t: goto skip_t
net use t: /del
:skip_t

net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!

Or how about this version:

@echo off
cls
if exist p: net use p: /del
if exist s: net use p: /del
if exist t: net use t: /del

net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!

If more than one statement needs to be executed in each block, this can be
achieved like this:

if exist p: echo/disconnecting drive P: & net use p: /del

or like this:

if exist p: (
echo/disconnecting drive P:
net use p: /del
)


/Al
 
A

Al Dunbar

foxidrive said:
@echo off
cls
if exist p: net use p: /del
if exist s: net use s: /del
if exist t: net use t: /del
net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!

Sheesh, Al, read first *then* post!

/Al
 
T

Todd Vargo

Al said:
Or how about this version:

@echo off
cls
if exist p: net use p: /del
if exist s: net use p: /del
if exist t: net use t: /del

net use p: \\airnas\default mypassword /user:airnas\default
net use s: \\airnas\public
net use t: \\airnas\usb_disk\usb_c
echo DONE!

Well done! I guess pointing out the erroneous use of multiple labels with
If more than one statement needs to be executed in each block, this can be
achieved like this:

if exist p: echo/disconnecting drive P: & net use p: /del

IMO, does not fall into the "look better" description".

or like this:

if exist p: (
echo/disconnecting drive P:
net use p: /del
)

Yes, this way is better, however, I still use Windows 98 so still seem to
use universal code.
 
B

bwawawa

Well done! I guess pointing out the erroneous use of multiple labels with
same name was of greater concern to me. <shrug>





IMO, does not fall into the "look better" description".





Yes, this way is better, however, I still use Windows 98 so still seem to
use universal code.

Thanks folks. I got scared when I saw Rob Vanderwoude batch file
sample.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top