home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lsmt213c.zip / ls2nt.cmd < prev    next >
OS/2 REXX Batch file  |  1998-06-01  |  8KB  |  224 lines

  1. /*---------------------------------------------------------------------------*\
  2. |   Lan Server assignments to NT server       (C) Alain Rykaert - MAY98-JUN98 |
  3. |                                                                             |
  4. |     Return Codes: 0 - ok                                                    |
  5. |                   1 - file not found                                        |
  6. |                   2 - copy error                                            |
  7. |                   3 - create dir error                                      |
  8. |                   4 - init error                                            |
  9. |                   5 - write error                                           |
  10. |                   6 - syntax error                                          |
  11. \*---------------------------------------------------------------------------*/
  12.     Version = '1.01'
  13.     Say '* LS2NT Version' Version 'running at' Date('E') Time()
  14.  
  15.  
  16.  /*====================================*/
  17.     OutDirName = '\\dc01\netlogon'                      /* Output Directory*/
  18.     OutDirName = 'x:\netlogon'                          /* Output Directory*/
  19.  /*====================================*/
  20.  
  21.     Say '* Output Directory Name:' OutDirName
  22.  
  23.     Parse Upper Arg DCName Option
  24.  
  25.     Call Init                                 /* init dll's and other stuff*/
  26.  
  27.     If DCName = ''
  28.       Then Do
  29.              Say '*'
  30.              Say '* Lan Server to NT Logon Assignments'
  31.              Say '*'
  32.              Say '* Usage: LS2NT {DCName} {/T]'
  33.              Say '*'
  34.              Say '* Sample: GETSW \\BEDDC01'
  35.              Say '*'
  36.              Exit 6
  37.            End
  38.       Else Nop
  39.  
  40.     If DCName = '*'
  41.       Then Do
  42.              RC = NetGetInfo(350, 'WkstaInfo','')
  43.              If RC = 0
  44.                Then DCName = WkstaInfo.ComputerName
  45.                Else Exit 4
  46.            End
  47.       Else Nop
  48.  
  49.     DCName = Strip(DCName,'L','\')
  50.     If Trace Then Say '* Server Name:' '\\'DCName
  51.  
  52.     Call Time('R')                                       /* Reset the timer*/
  53.  
  54.     RC = NetGetInfo(370, 'ServerModalInfo', '\\'DCName)  /* get server role*/
  55.     If RC = 0
  56.       Then Do
  57.              ServerRole = ServerModalInfo.Role
  58.              If WordPos('Primary', ServerRole) > 0 |,
  59.                 WordPos('Backup', ServerRole) > 0
  60.                Then Nop
  61.                Else Do
  62.                       Say '! This is not a Primary Domain Controller' '07'x
  63.                       Exit 4
  64.                     End
  65.            End
  66.       Else Do
  67.              Say '! Error:' RC
  68.              Exit 4
  69.            End
  70.  
  71.     If Trace Then Say '* Getting all Aliases'
  72.  
  73.     RC = NetEnumerate(20, 'Alias', '\\'DCName)
  74.     If RC = 0
  75.       Then Do
  76.              If Trace Then Say '> Total number of aliases:' Alias.0
  77.              Call RxStemSort 'Alias'
  78.              AllAliases = ''
  79.              Do i = 1 To Alias.0
  80.                AllAliases = AllAliases Alias.i
  81.                Call NetGetInfo 20, 'AliasInfo', '\\'DCName, Alias.i
  82.                Alias.i.1 = Translate(AliasInfo.Server)
  83.                Alias.i.2 = Translate(AliasInfo.Netname)
  84.              End
  85.            End
  86.       Else Do
  87.              Say '! Error:' RC
  88.              Exit 4
  89.            End
  90.  
  91.     If Trace Then Say '* Getting all users'
  92.  
  93.     RC = NetEnumerate(280, 'UserID', '\\'DCName)
  94.     If RC = 0
  95.       Then Do
  96.              If Trace Then Say '> Total number of users:' UserID.0
  97.              Call RxStemSort 'UserID'
  98.              If Trace Then Say '* Get all users with a logon assignment'
  99.              Do i = 1 to UserID.0
  100.                If Trace Then Say Copies('*', 60)
  101.                Counter = '('Right(i,Length(UserID.0))'/'Right(UserID.0,Length(UserID.0))')'
  102.                If Trace Then Say '> UserID:' Counter UserID.i
  103.                RC = NetGetInfo(52, 'LogonAsnInfo', '\\'DCName, UseriD.i)
  104.                If RC = 0 & LogonAsnInfo.Count > 0
  105.                  Then Do
  106.                         UserFileName = OutDirName'\'UserID.i'.CMD'
  107.                        'if exist' UserFileName 'del' UserFileName
  108.                         Call Logit UserFileName ' @ECHO OFF'
  109.  
  110.                         Call NetGetInfo 280, 'UserInfo', '\\'DCName, UserID.i
  111.                         If UserInfo.Home_Dir = '-none-'
  112.                           Then Nop
  113.                           Else Do
  114.                                  Parse Value UserInfo.Home_Dir With DriveLetter '\' HSName '\' Resource
  115.                                  HSName = Strip(HSName,'L','\')
  116.                                  Text = ' NET USE' DriveLetter '\\'HSName'\'Resource
  117.                                  Call Logit UserFileName Text
  118.                                End
  119.  
  120.                         Do j = 1 to LogonAsnInfo.Count
  121.                           x = WordPos(LogonAsnInfo.j.Alias, AllAliases)
  122.                           If Length(LogonAsnInfo.j.Device) = 1
  123.                             Then Device.j = Translate(LogonAsnInfo.j.Device) || ':'
  124.                             Else Device.j = Translate(LogonAsnInfo.j.Device)
  125.                           Server.j = Alias.x.1
  126.                           NetName.j = Alias.x.2
  127.                           Text = ' NET USE' Device.j '\\'Server.j'\'NetName.j
  128.                           Call Logit UserFileName Text
  129.                         End
  130.                       End
  131.                  Else Nop
  132.              End
  133.            End
  134.       Else Do
  135.              Say '! Error:' RC
  136.              Exit 4
  137.            End
  138.  
  139.     Say '* LS2NT Ended:' Trunc(Time('E'),2)
  140.  
  141.     Exit 0
  142.  
  143.  INIT:/* --------------------------------------------------------------------*/
  144.  
  145.    '@echo off'
  146.  
  147.     If Option <> '/T'                          /* if trace option specified*/
  148.       Then Do
  149.              Trace = 0
  150.              Redir = '>nul 2>nul'
  151.            End
  152.       Else Do
  153.              Trace = 1
  154.              Redir = '>con 2>con'
  155.            End
  156.  
  157.     BootDrive = Left(Value('Comspec',,'OS2Environment'),2)
  158.  
  159.     If RxFuncQuery('SysLoadFuncs')
  160.       Then Do
  161.              Call RxFuncAdd SysLoadFuncs, RexxUtil, SysLoadFuncs
  162.              Call SysLoadFuncs
  163.            End
  164.       Else Nop
  165.  
  166.     LSRDrive = ''                      /* Check for Lan Server Drive Letter*/
  167.     PPath = Translate(Value('PATH',,'OS2Environment'))
  168.     x = Pos('\IBMLAN\NETPROG;', PPath) -2
  169.     If x > 0
  170.       Then LSRDrive = SubStr(PPath, x, 2)
  171.       Else Do
  172.              Say '! Could not determine the Lan Requester path' '07'x
  173.              Exit 4
  174.            End
  175.  
  176.     Call ChkFile LSRDrive'\ibmlan\netlib\lsrxut.dll'
  177.     If RxFuncQuery('LoadLSRXUTFuncs')
  178.       Then Do
  179.              Call RxFuncAdd LoadLsRxutFuncs, LSRXUT, LoadLsRxutFuncs
  180.              Call LoadLsRxutFuncs
  181.            End
  182.       Else Nop
  183.  
  184.     Call ChkFile BootDrive'\os2\dll\rxutils.dll'
  185.     If RxFuncQuery('RxLoadFuncs')
  186.       Then Do
  187.              Call RxFuncAdd RxLoadFuncs, RXUTILS, RxLoadFuncs
  188.              Call RxLoadFuncs
  189.            End
  190.       Else Nop
  191.  
  192.     TempFile = LSRDrive'\ibmlan\ls2nt.tmp'                /* Temporary file*/
  193.  
  194.     Return
  195.  
  196.  CHKFILE:/* -----------------------------------------------------------------*/
  197.  
  198.     Parse Arg File_To_Check
  199.  
  200.     If Stream(File_To_Check, 'C', 'Query Exists') = ''
  201.       Then Do
  202.              Say '! File not found:' File_To_Check '07'x
  203.              Exit 1
  204.            End
  205.       Else Nop
  206.  
  207.     Return
  208.  
  209.  LOGIT:/* - -----------------------------------------------------------------*/
  210.  
  211.     Parse Arg OutFileName OutText
  212.  
  213.     If Trace Then Say ' ' OutFileName OutText
  214.  
  215.     If LineOut(OutFileName, OutText) = 0
  216.       Then Call Stream OutFileName, 'C', 'Close'
  217.       Else Do
  218.              Say '! Error while writing:' OutFileName '07'x
  219.              Exit 5
  220.            End
  221.  
  222.     Return
  223.  
  224.