Tuesday, 12 November 2013

What is the difference between a Mapped drive and a simple network share?

The popular internet answer appears to be "very little".

 

But if you are trying to install crappy educational software on a Windows network, you may need to create a mapped drive on any local computers to get it to work.


As I discovered this week, some Windows applications appear to be written such that they expect a mapped drive, rather than simply allowing a user to use a straightforward path to a server shared folder.

The problem with this is that on an established network, drive letters are often reserved for specific uses. So you can't afford to hand out drive letters for all these demanding little applications.

On the network in question, mapped drives are automatically assigned as the user logs on, based upon OU. So although there may be (say) 20 standard drive letter assignments for this network, on an individual computer after log on, there may only be a subset of maybe 10 listed.

In addition, no user is likely to want to run all of the network applications that require local mapped drives. So the solution I came up with, was to dynamically map a drive using an available drive letter when one of these applications is requested. When a user logs out of a session, all mapped drives are lost, and then only the required standard drives are re-establish when a user logs on.

The command prompt "net use" command turns out to be very useful. If we run it in this form:-

net use * {network folder share}

...Windows will automatically assign an available drive letter to the specified share. We can then use this drive assignment to run the required program.

Here is my VB script implementation of this idea:-

'***************************************************************
'RunSomeApp.vbs
'This script creates a mapped drive on a local machine, allowing

'a specified app to run from a server without having
'to use a permanent mapped drive.
'Captain Bodgit
'November 2013
'===============================================================

Dim strCommandDrive   'command to create a mapped drive for the target shared folder
Dim strCommandRun     'command to run the target application
Dim FSO               'Our new instance of FileSystemObject
Dim strMappedDrive    'the new mapped drive, e.g. z:

On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")

strCommandDrive = "net use * " & """\\appServer\Bodgit"""
Set objExecObject = WshShell.Exec (strCommandDrive)

strMappedDrive = objExecObject.StdOut.Readline()

if Instr(strMappedDrive, ":") > 0 then  'successfully mapped a drive
    strMappedDrive=Mid(strMappedDrive,Instr(strMappedDrive, ":")-1, 2) 'pick out the letter & colon
   
    strCommandRun = strMappedDrive & "\theApp.exe"        'the target exe
    WshShell.Run strCommandRun            'Run the exe
Else
    Msgbox "Can't find mapped drive",16,"Uh-Oh!"
End If

Set objExecObject = Nothing
Set WshShell = Nothing


So create a script for each application where a mapped drive is required and save with the network application. Now when the user runs the script from the network location on a local computer, the application should load and run!



No comments:

Post a Comment