We help IT Professionals succeed at work.

Batch script for temporary mapped net drive

GisGeek
GisGeek asked
on
15,353 Views
Last Modified: 2012-06-27
Does anyone know the syntax for a batch that will do the following?:
1. check to see if a mapped drive exists
2. if so, validate that a file exists on the remote drive
3. if neither, create map with a specified drive letter
4. if server not found, return gui error message
5. only if both successful, launch executeable on the mapped drive
6. delete the mapped drive when the program is exited and don't prompt for y/n
7. return gui message if map successfully deleted

This script is for a doc mgmt prog. This works, but it is missing the delete drive and file check portions:

net use K: /d
net use K: \\servername\sharename /user:username password /persistent:no
K:\sharename\executeable

Thanks.
Comment
Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks Sirbounty and Thrasymachus,
I used some of both, plus a gui input freeware found at :
http://home.pe.net/~fpw/freeware   -- called popup.zip
 There are two text notifications that control the batch with y/n user input from the gui popup. Also added a notifier to a workgroup that a user couldn't ping the server. And added a fake delay for the user to retry the connection in one minute--y/n. And added a user input for successfull, continue? --y/n. The only thing I couldn't work out was the delete map after program exit. So I hid the K drive using Tweakui and relied on the 15 minute timeout to free up resources for other users

Final syntax:

@echo off
if not exist K:\ net use K: \\servername\share /user:namehere passwordhere /persistent:no

:ping
ping servername || goto notfound
goto runit

:runit
if exist K:\sharename\program.exe goto notifygood
if not exist K:\sharename\program.exe goto remap
goto end

:remap
net use K: /del /yes
net use K: \\servername\share /user:namehere passwordhere /persistent:no
if exist K:\sharename\program.exe goto runit
if not exist goto notifybad

:notifybad
popup /OKC /B1 /T:ServerUnavailable /MF notifybad.txt  
IF ERRORLEVEL 2 GOTO end
PING 1.1.1.1 -n 60 -w 1000 >NUL
goto runit

:notifygood
popup /OKC /B1 /T:ConnectionEstablished... /MF viewconnect.txt
IF ERRORLEVEL 2 GOTO stop  
start K:\sharename\program.exe

:stop
cls
exit

:notfound
net send %computername% Fortis Server not found! Please contact your system administrator.
net send /domain:gis Above client is having trouble connecting to Fortis Server.

:end
@echo off
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.