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_redirect()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 LM_REDIRECT()
 Redirect a network device
------------------------------------------------------------------------------

 Syntax

      LM_Redirect( <cLocalName>, <cRemoteName> [,<cPassword>] ) -> lSuccess

 Arguments

     <cLocalName> is a local printer port name (for example "LPT3:") or
     a drive letter (for example "X:"). The port name or drive letter must
     not be in use in another existing redirection. If it is, you must
     first cancel that redirection with LM_KillRedir(). The range of
     valid printer port names ("LPT1:" up to "LPTn:") may vary between
     different operating system versions. The range of valid disk drive
     letters may vary depending on the LASTDRIVE= setting in the OS.

     <cRemoteName> is the share name of the remote device you want to
     connect to in "\\<computername>\<resourcename>" format, for example
     "\\MYSERVER\MYPRINTER".

     <cPassword> is an optional password needed for connecting to the
     remote device.

 Returns

     <lSuccess> which is set to .T. if the operation succeeded and .F.
     if it did not succeed

 Description

     LM_Redirect() is used to redirect a shared printer or disk drive to
     a local printer port name or drive letter. It works identically to
     the "NET USE" DOS command (the original, simple DOS 3.1 version of
     "NET USE", to be exact). It does not support the /PERSISTENT option.

     The optional password will not work for logging into a domain. It is
     only meant for connecting to a share which was assigned a separate
     password when it was shared. This type of password protection is known
     as "share level security" as opposed to "user level security" when a
     user logs in with his or her personal password.

     LM_Redirect() calls the DOS 3.1 networking function 5F03h to perform
     the redirection If the function call fails, the DOS error code can
     be retrieved by calling LM_Ferror().

     LM_Redirect() 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

     // This example connects to a shared printer and sets it up as
     // LPT3: after first checking with LM_GetRedir() that no other
     // redirection is set up using the same local printer port name:
     //
     #include "LMLIB.CH"
     local cLocalName := 'LPT3:'
     local cRemoteName := '\\MYSERVER\MYPRINTER'
     local aRedirList := {}
     local lSuccess
     aRedirList := LM_GetRedir(,cLocalName)   // 1st argument is NIL!!
     if empty(aRedirList)  // LPT3: was not found in the redirection list
        lSuccess := LM_Redirect(cLocalName, cRemoteName)
        if lSuccess
           ? 'The shared printer "' + cRemoteName + '"'
           ? 'was redirected to "' + cLocalName + '"'
        else
           ? 'Could not perform the redirection (Error ' +;
           ltrim(str(LM_Ferror())) + ')'
        endif
     else
        // One redirection list entry was returned by LM_GetRedir(). The
        // local name of that redirection is by definition 'LPT3:'
        if aRedirList[1,LM_REDLIST_REMOTE] == cRemoteName
           ? 'The desired redirections is already in place!'
        else
           ? 'The local name "' + cLocalName + '" is already in use for'
           ? 'the redirection of "' + aRedirList[1,LM_REDLIST_REMOTE] + '"'
        endif
     endif
     //
     // This example does basically the same thing, but if the shared
     // resource in question is already redirected using another printer
     // port name, it uses the existing redirection instead of creating
     // a new one:
     //
     #include "LMLIB.CH"
     local cLocalName := 'LPT3:'
     local cRemoteName := '\\MYSERVER\MYPRINTER'
     local aRedirList := {}
     local lSuccess
     aRedirList := LM_GetRedir(,cRemoteName)   // 1st argument is NIL!!
     if empty(aRedirList)
        // '\\MYSERVER\MYPRINTER' was not found in the redirection list
        lSuccess := LM_Redirect(cLocalName, cRemoteName)
        if lSuccess
           ? 'The shared printer "' + cRemoteName + '"'
           ? 'was redirected to "' + cLocalName + '"'
        else
           ? 'Could not perform the redirection (Error ' +;
           ltrim(str(LM_Ferror())) + ')'
        endif
     else
        // One redirection list entry was returned by LM_GetRedir()
        // and that entry contains the printer we want, but it is
        // possibly redirected to another local printer port name
        if aRedirList[1,LM_REDLIST_LOCAL] == cLocalName
           ? 'The desired redirections is already in place!'
        else
           cLocalName := aRedirList[1,LM_REDLIST_LOCAL]
           ? 'The printer is already redirected using the local printer'
           ? 'port name "' + cLocalName + '", so we will use that local'
           ? 'name for printing instead'
        endif
     endif
     //
     // This example redirects a password protected disk drive to a
     // local drive letter (forgetting to check first if the local
     // name is free or not...):
     //
     local cLocalName := 'X:'
     local cRemoteName := '\\MYSERVER\TOPSECRET'
     local cPassword := 'SPY_HARD'
     local lSuccess
     lSuccess := LM_Redirect(cLocalName, cRemoteName, cPassword)
     if lSuccess
        ? 'The shared disk "' + cRemoteName + '"'
        ? 'was redirected to "' + cLocalName + '"'
     else
        ? 'Could not perform the redirection (Error ' +;
        ltrim(str(LM_Ferror())) + ')'
     endif

 Source: REDIRECT.PRG

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

See Also: LM_KillRedir() LM_GetRedir()

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