Computing.Net > Forums > Windows XP > batch check if network source is av

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch check if network source is av

Reply to Message Icon

Name: Michel123321
Date: March 30, 2009 at 03:39:39 Pacific
OS: Windows Vista/XP
Subcategory: Configurations
Comment:

Hello,

I'm creating a batch which adds network drives. for a user when it logs on.
I got the script this far that it will check if the drive already exists and if it does it will be deleted and created again.

But how do I check if the network source is available?
If the server is offline the network drive can't be created..

this is the script I have so far

@echo off
if not exist X:\nul goto NOT_EXIST
MD X:\mytemp
if not exist X:\mytemp\nul goto NOT_READY
Rmdir X:\mytemp
net use X: /delete
goto create_X

:NOT_EXIST
net use X: \\[servername]\data\users\post
echo Drive X:\ is aangemaakt.
goto next

:NOT_READY
echo Drive X:\ is nog niet klaar!
goto fout

:create_X
net use X: \\[servername]\data\users\post
echo Drive X:\ is aangemaakt.
goto next

:fout
pause
echo Er is een fout opgetreden bij het aanmaken van drive X:\, neem AUB contact op met uw systeem beheerder
goto end

:next
if not exist W:\nul goto W_NOT_EXIST
MD W:\mytemp
if not exist W:\mytemp\nul goto W_NOT_READY
rmdir W:\mytemp
net use w: /delete
goto create_w

:W_NOT_EXIST
net use w: \\[servername]\data\users\archief
echo Drive W:\ is aangemaakt.
goto end

:W_NOT_READY
echo Drive W:\ is nog niet klaar!
goto fout

:create_w
net use w: \\[servername]\data\users\archief
echo Drive w:\ is aangemaakt.
goto end

:end

As you can see there are 2 network drives created X and W, if they already exist they will be deleted and again created. but if the network source is unavailable the creation will result in an error.

Is it possible to do a check on a network source? like this

if not exist \\[servername]\data\users\post goto fout

I hope someone can help me with this.

Greetz Michel



Sponsored Link
Ads by Google

Response Number 1
Name: Michel123321
Date: March 30, 2009 at 04:01:06 Pacific
Reply:

In the meanwhile I had the time to test some things out. and it seems that it works to check a network path with
if no exist \\[servername]\data\users goto fout

I also perfected the script a lill more. if someone has tips it would be great!!

@echo off
if not exist X:\nul goto create_X
MD X:\mytemp
if not exist X:\mytemp\nul goto NOT_READY
Rmdir X:\mytemp
net use X: /delete
goto create_X

:NOT_READY
echo Drive X:\ is nog niet klaar!
goto fout_X

:create_X
if not exist \\[servername]\data\users\post goto fout_X
net use X: \\[servername]\data\users\post
echo Drive X:\ is aangemaakt.
goto next

:fout_X
echo Er is een fout opgetreden bij het aanmaken van drive X:\ neem AUB contact op met uw systeem beheerder
pause
goto next

:next
if not exist W:\nul goto create_w
MD W:\mytemp
if not exist W:\mytemp\nul goto W_NOT_READY
rmdir W:\mytemp
net use w: /delete
goto create_w


:W_NOT_READY
echo Drive W:\ is nog niet klaar!
goto fout_w

:create_w
if not exist \\[servername]\data\users\archief goto fout_W
net use w: \\[servername]\data\users\archief
echo Drive w:\ is aangemaakt.
goto end

:fout_w
echo Er is een fout opgetreden bij het aanmaken van drive W:\ neem AUB contact op met uw systeem beheerder
pause
goto end

:end


0

Response Number 2
Name: kptech
Date: March 30, 2009 at 05:41:07 Pacific
Reply:

Yes, you are correct in you observation.

As long as the user is logged-on and permissions allow the user access to the server resource, it IS valid to use UNC file names in a batch file.


0

Response Number 3
Name: Michel123321
Date: March 30, 2009 at 06:06:28 Pacific
Reply:

The users that the batch file aplies to do have access to these network resources. (They have the neccesairy permissions so no user authentication is required.)

If my observations are correct this line
if not exist \\[servername]\data\users goto fout
will check if they can establish a connection to the server.
If this check failes you'll get an error which stays in the screen with the Pause command.
If all goes smoothly the user will barely notice the script.

Still haven't got the change to test out the script in the actual business envoirment. But I've created a 2nd (simpler one) to test in my own envoirment. It seems to work just fine.
The thing is that I don't know how the script will react on other warnings...


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: batch check if network source is av

commannd to check if xp is register www.computing.net/answers/windows-xp/commannd-to-check-if-xp-is-register/85550.html

To check if tape is full www.computing.net/answers/windows-xp/to-check-if-tape-is-full-/98981.html

Network Cable Unplugged Error www.computing.net/answers/windows-xp/network-cable-unplugged-error/54779.html