Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- LanMan Library Reference Guide - <b>lm_getredir()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 LM_GETREDIR()
 Get the redirection list
------------------------------------------------------------------------------

 Syntax

      LM_GetRedir( [<nDeviceType>] [,<cDeviceName>] ) -> aRedirList

 Arguments

     <nDeviceType> is an optional device type selection. It can be set to
     return either printers or disk drives. If <nDeviceType> is omitted or
     an invalid device type is specified, both device types will be
     returned.

     Use the following #defines from LMLIB.CH for device type selection:
     Printers       LM_DEVICE_PRINT      3
     Disk drives    LM_DEVICE_DISK       4

     <cDeviceName> is an optional device name to search for in the
     redirection list. If the specified device name is found, that device
     -  and only that device  -  will be returned. If the specified device
     name is not found, en empty <aRedirList> will be returned. If the
     device is redirected more than once, only the first redirection found
     in the redirection list will be returned.

     The device name specified in the <cDeviceName> argument can be either
     a local name (for example "LPT3:" or "X:") or a remote name (for
     example "\\MYSERVER\MYPRINTER"). LM_GetRedir() will inspect the first
     two characters in the argument and search for a remote name if they
     are "\\" or a local name if they are not.

     If <cDeviceName> is passed, LM_GetRedir() does not care about the
     value of <nDeviceType>.

 Returns

     <aRedirList> which is a two-dimensional array of redirected devices.
     For each device (the first array dimension) a sub-array of the
     following structure (the second array dimension) is returned. The
     #defines can be found in the LMLIB.CH header file:

     Element #1  LM_REDLIST_LOCAL   Character Local device name
     Element #2  LM_REDLIST_REMOTE  Character Remote device name
     Element #3  LM_REDLIST_DEVTYPE Numeric   Device type (Printer/disk)
     Element #4  LM_REDLIST_STATUS  Numeric   Device status (Valid/invalid)

     The local device name is a printer port name (for example "LPT3:")
     or a drive letter (for example "X:". It is returned with a trailing
     colon whether the OS itself reports one or not.

     The remote device name is the share name of the device including the
     name of the server sharing it (for example "\\MYSERVER\MYPRINTER").

     The device types are reported identically to how they are specified
     in the <nDeviceType> argument and can be retrieved using the same
     #defines.

     The device status, reported by the "NET USE" command as either "OK"
     or "Disconnected" in English DOS versions, can be retrieved using the
     following #defines:

     Valid/OK               LM_DEVICE_VALID       0
     Invalid/Disconnected   LM_DEVICE_INVALID     1

     If no redirected devices are found or the optional <cDeviceName>
     argument is specified but does not match an entry in the redirection
     list, an empty array will be returned.

 Description

     LM_GetRedir() retrieves the redirection list, that is, the list of
     redirected devices in the local computer. You can get either the
     complete list including both printers and disk drives or you can
     specify that you want only one of the device types.

     By optionally passing the share name of a remote device in the second
     argument, you can easily check if that share is already redirected
     and, if so, under which local name. Or you can check if a local name
     is already "occupied" by an existing redirection by specifying that
     local name.

     A remote name must always begin with two backslashes and there must be
     one backslash between the server name and the device name. There must
     be no trailing backslash. A local name must have a trailing colon and
     no trailing backslash.

     LM_GetRedir() calls the DOS 3.1 networking function 5F02h repeatedly
     to get the redirection list, one entry at a time. If the function call
     fails, an empty array will be returned. The DOS error code can then be
     retrieved by calling LM_Ferror(). Only a failure in the first call is
     actually considered a failure. If the call to DOS function 5F02h fails
     in a later iteration, it only means that the end of the redirection
     list has been reached.

     LM_GetRedir() requires FT_Int86() and supporting functions from
     the Nanforum Toolkit and its companion CPMI library. It is supposed
     to work on any computer running DOS 3.1 or higher.

 Examples

     #include "LMLIB.CH"
     local i
     local aRedirList := {}
     //
     // This will return the whole redirection list:
     aRedirList := LM_GetRedir()
     //
     // Uncomment this version instead if you want printers only:
     // aRedirList := LM_GetRedir(LM_DEVICE_PRINT)
     //
     // ... or this version if you want disk drives only:
     // aRedirList := LM_GetRedir(LM_DEVICE_DISK)
     //
     // Note the absence of the first argument in the following examples
     // (You may of course specify NIL instead of skipping it):
     //
     // This version will return whatever printer is redirected to
     // LPT3: or an empty array if there is no such redirection:
     // aRedirList := LM_GetRedir(,'LPT3:')
     //
     // This version will return whatever disk is redirected to
     // X: or an empty array if there is no such redirection:
     // aRedirList := LM_GetRedir(,'X:')
     //
     // With this version you can find out whether \\MYSERVER\MYPRINTER
     // is redirected or not, and if it is, what the local name is:
     // aRedirList := LM_GetRedir(,'\\MYSERVER\MYPRINTER')
     //
     // With this version you can find out whether \\MYSERVER\MYDISK
     // is redirected or not, and if it is, what the local name is:
     // aRedirList := LM_GetRedir(,'\\MYSERVER\MYDISK')
     //
     // OK, let's get on with it and see what we found:
     //
     if !empty(aRedirList)
        for i := 1 to len(aRedirList)
           ? iif(aRedirList[i,LM_REDLIST_STATUS] == LM_DEVICE_VALID,;
           'OK'+space(12),'Disconnected'+space(2))
           ?? iif(aRedirList[i,LM_REDLIST_DEVTYPE] == LM_DEVICE_PRINT,;
           'Printer'+space(2),'Disk'+space(5))
           ?? left(aRedirList[i,LM_REDLIST_LOCAL]+space(7),7)
           ?? aRedirList[i,LM_REDLIST_REMOTE]
        next
     else
        ? 'Could not get the redirection list (Error ' +;
        ltrim(str(LM_Ferror())) + ')'
     endif

 Header File: LMLIB.CH

 Source: GETREDIR.PRG

 Author: Klas Engwall <klas.engwall@engwall.com>

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson