Richard Parmiter

Virtualisation blog and Knowledge Base

  • You are here: 
  • Home
  • How to: Only map a drive if the server is up

How to: Only map a drive if the server is up

Posted on September 1st, 2008

Logon scripts can be used to map drives for users. The general rule of thumb is to script in either vbs/kix/cmd files and first delete an existing mapping on the specified drive letter and map the drive as shown:

net use P: /delete

net use P: \\server.fqdn.local\share

There can be a delay in the logon time if this server doesn’t exist or is down for whatever reason. If there are many drive mappings during the logon process the delay can be substancial. To get round this problem a script can be run to only map a drive letter if the server is up.

This script is for a dos based cmd script although the same principle can be used for the other scripting technologies. The general process would take:

  • Ping the server (once or more if needed)
  • Save the ping results to a file (e.g. ping.txt)
  • search the file for ‘request timed out)
  • only map the drive if this doesn’t exist
  • delete the temporary ping.txt file.

Command file

@echo off
net use p: /delete
ping server.fqdn.local -n 1 > z:\citrix\ping.txt
findstr “Request timed out” z:\citrix\ping.txt
IF ERRORLEVEL 1 net use P: “\\server.fqdn.local\share”
del z:\citrix\ping.txt

Kix version (doesn’t require a temporary file)

Shell ‘%comspec% /c ping server.fqdn.local -n 1 | find “TTL” > nul’
If not @ERROR
? “Ping reply was good”
use P: “\\server.fqdn.local\share”
Else
? “Ping reply was bad”
EndIf

  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites
  • FriendFeed
  • Google Buzz
  • LinkedIn
  • Live
  • MySpace
  • Reddit
  • RSS

Tags: , , , ,
Filed under Scripts/Reg |

Leave a Reply

*