home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lsmt213c.zip / lsalias.cmd < prev    next >
OS/2 REXX Batch file  |  2000-02-16  |  10KB  |  260 lines

  1. /*---------------------------------------------------------------------------*\
  2. |  Browse or change Alias Name & Assignments  (C) Alain Rykaert - NOV97-FEB98 |
  3. \*---------------------------------------------------------------------------*/
  4.     Version = '1.04'
  5.     Say '* LSALIAS Version' Version
  6.  
  7.     Parse Upper Arg DCName OldAliasName NewAliasName
  8.  
  9.     Call Init                                   /* load DLL's & other stuff*/
  10.  
  11.     LogFileName = 'LSALIAS.LOG'                     /* name of the log file*/
  12.  
  13.     If DCName = '' | OldAliasName = ''
  14.       Then Do
  15.              Say '*'
  16.              Say '* Browse or Change an Alias name & logon assignments'
  17.              Say '*'
  18.              Say '* Browse: LSALIAS {PrimaryDomainController} {AliasName}'
  19.              Say '* Sample: LSALIAS \\DC01 ALIAS1'
  20.              Say '*'
  21.              Say '* Change: LSALIAS {PrimaryDomainController} {OldAliasName} {NewAliasName}'
  22.              Say '* Sample: LSALIAS \\DC01 ALIAS1 ALIAS01'
  23.              Say '*'
  24.              Exit
  25.            End
  26.       Else Nop
  27.  
  28.     DCName = Strip(DCName,'L','\')
  29.  
  30.     Say '* Check if \\'DCName 'is a Primary Domain Controller'
  31.     RC = NetGetInfo(370, 'ServerModalInfo', '\\'DCName)
  32.     If RC = 0
  33.       Then Do
  34.              ServerRole = ServerModalInfo.Role
  35.              If WordPos('Primary', ServerRole)
  36.                Then Nop
  37.                Else Do
  38.                       Say '! This is not a Primary Domain Controller' '07'x
  39.                       Call ChkError '! Error:' DCName 'not a Primary DC'
  40.                     End
  41.            End
  42.       Else Call ChkError '!' DCName RC
  43.  
  44.     Say '* Get information from the (old) Alias' OldAliasName
  45.     RC = NetGetInfo(20, 'AliasInfo', '\\'DCName, OldAliasName)
  46.     If RC = 0
  47.       Then Do
  48.              Call Logit 'Name       :' AliasInfo.Name
  49.              Call Logit 'Remark     :' AliasInfo.Remark
  50.              Call Logit 'Server     :' AliasInfo.Server
  51.              Call Logit 'NetName    :' AliasInfo.Netname
  52.              Call Logit 'Location   :' AliasInfo.Location
  53.              Call Logit 'Mode       :' AliasInfo.Mode
  54.              Call Logit 'Max uses   :' AliasInfo.Maxuses
  55.              Call Logit 'Type       :' AliasInfo.Type
  56.              Call Logit 'Queue      :' AliasInfo.Queue
  57.              Call Logit 'Path       :' AliasInfo.Path
  58.              Call Logit 'Priority   :' AliasInfo.Priority
  59.              Call Logit 'Device pool:' AliasInfo.Device_pool
  60.            End
  61.       Else Call ChkError '! Error: Alias info' OldAliasName RC
  62.  
  63.     Say '* Get all users from \\'DCName
  64.  /* RC = NetEnumerate(280, 'UserID', '\\'DCName) */
  65.     RC = WfrxUserEnum('\\'DCNAME,'USERID')
  66.     If RC = 0
  67.       Then Do
  68.              Say '* Total number of users:' UserID.0
  69.              If RXUtils                         /* if RXutils DLL available*/
  70.                Then Call RxStemSort 'UserID'
  71.                Else Nop
  72.  
  73.              Say '* Get all users with a logon assignment to the Alias' OldAliasName
  74.              k = 0
  75.              Do i = 1 to UserID.0
  76.                Counter = '('Right(i,Length(UserID.0))'/'Right(UserID.0,Length(UserID.0))')'
  77.                Call NetGetInfo 52, 'LogonAsnInfo', '\\'DCName, UseriD.i
  78.                If LogonAsnInfo.0 > 0
  79.                  Then Do j = 1 to LogonAsnInfo.0
  80.                         If LogonAsnInfo.j.Alias = OldAliasName
  81.                           Then Do
  82.                                  k = k + 1
  83.                                  FoundUserID.k = UserID.i
  84.                                  FoundDevice.k = LogonAsnInfo.j.Device
  85.                                  Text = Counter Left(UserID.i,8) LogonAsnInfo.j.Device
  86.                                  Call Logit Text
  87.                                End
  88.                           Else Nop
  89.                         LogonAsnInfo.j.Alias = ''
  90.                       End
  91.                  Else Nop
  92.              End
  93.              FoundUserID.0 = k
  94.            End
  95.       Else Call ChkError '! Error: User info' OldAliasName RC
  96.  
  97.     If NewAliasName = ''   /* if no new alias specified, exit the procedure*/
  98.      Then Signal Quit
  99.      Else Nop
  100.  
  101.     Say '* Check if the new alias' NewAliasName 'already exist'
  102.     RC = NetGetInfo(20, 'AliasInfo', '\\'DCName, NewAliasName)
  103.     If RC = 0
  104.       Then Call ChkError '! Error: Alias' NewAliasName 'already exist'
  105.       Else Nop
  106.  
  107.     Say '* Add new Alias definitions' NewAliasName
  108.     AliasInfo.Name = NewAliasName
  109.     RC = NetAdd(20, 'AliasInfo', '\\'DCName)
  110.     If RC = 0
  111.       Then Call Logit 'Alias' NewAliasName 'added'
  112.       Else Call ChkError '! Error: Add alias' NewAliasName RC
  113.  
  114.     Say '* Delete old Alias definitions' OldAliasName
  115.     RC = NetDelete(20, '\\'DCName, OldAliasName)
  116.     If RC = 0
  117.       Then Call Logit 'Alias' OldAliasName 'deleted'
  118.       Else Call ChkError '! Error: Delete alias' OldAliasName RC
  119.  
  120.     Say '* Update logon assignments'
  121.     Do i = 1 to FoundUserID.0
  122.       Counter = '('Right(i,Length(FoundUserID.0))'/'Right(FoundUserID.0,Length(FoundUserID.0))')'
  123.       Say ' ' Counter Left(FoundUserID.i,8) FoundDevice.i
  124.       RC = NetDelete(52, '\\'DCName, FoundUserID.i, OldAliasName)
  125.       If RC = 0
  126.         Then Nop
  127.         Else Call ChkError '! Error: Delete logonassignment' FoundUserID.i FoundDevice.i RC
  128.       RC = NetAdd(52, '\\'DCName, NewAliasName, FoundDevice.i, FoundUserID.i)
  129.       If RC = 0
  130.         Then Nop
  131.         Else Call ChkError '! Error: Add logonassignment' FoundUserID.i FoundDevice.i RC
  132.     End
  133.  /*
  134.     Say '* Check the share status for' OldAliasName 'on \\'AliasInfo.Server
  135.     RC = NetGetInfo(190, 'ShareInfo', '\\'AliasInfo.Server, AliasInfo.NetName)
  136.     If RC = 0
  137.       Then Do
  138.              Call Logit 'Netname       :' ShareInfo.NetName
  139.              Call Logit 'Type          :' ShareInfo.Type
  140.              Call Logit 'Remark        :' ShareInfo.Remark
  141.              Call Logit 'Max uses      :' ShareInfo.Max_Uses
  142.              Call Logit 'Current uses  :' ShareInfo.Current_Uses
  143.              Call Logit 'Path          :' ShareInfo.Path
  144.              If ShareInfo.Current_Uses = 0       /* if share in use, log it*/
  145.                Then Nop
  146.                Else Do
  147.                       Call Logit '! Warning: Share in use ('ShareInfo.Current_Uses') on \\'AliasInfo.Server AliasInfo.NetName
  148.                       Say '* Press any key to continue' '07'x
  149.                       Pull
  150.                     End
  151.              RC = NetDelete(190, '\\'AliasInfo.Server, AliasInfo.NetName)
  152.              If RC = 0
  153.                Then Do
  154.                       ShareInfo.NetName = NewAliasName
  155.                       RC = NetAdd(190, 'ShareInfo', '\\'AliasInfo.Server)
  156.                       If RC = 0
  157.                         Then Nop
  158.                         Else Call ChkError '! Error: Add share on \\'AliasInfo.Server AliasInfo.NetName RC
  159.                     End
  160.                Else Call ChkError '! Error: Delete share on \\'AliasInfo.Server AliasInfo.NetName RC
  161.            End
  162.       Else Call ChkError '! Error: Share info' AliasInfo.NetName 'on' AliasInfo.Server RC
  163.    */
  164.  QUIT:
  165.  
  166.     Say '* Log File' LogFileName 'created'
  167.  
  168.     Exit
  169.  
  170.  INIT:/* --------------------------------------------------------------------*/
  171.  
  172.    '@echo off'
  173.     BootDrive = Left(Value('COMSPEC',,'OS2ENVIRONMENT'),2)
  174.  
  175.     If RxFuncQuery('SysLoadFuncs')
  176.       Then Do
  177.              Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  178.              Call SysLoadFuncs
  179.            End
  180.       Else Nop
  181.  
  182.     LSRDrive = Left(SysSearchPath('PATH', 'NET.EXE'), 2)    /* IBMLAN Drive*/
  183.     If LSRDrive <> ''
  184.       Then Nop
  185.       Else Do
  186.              Say '! Could not determine the Lan Requester path' '07'x
  187.              Exit X2D('1604')
  188.            End
  189.  
  190.     If Stream(LSRDrive'\ibmlan\netlib\lsrxut.dll', 'C', 'Query Exists') <> ''
  191.       Then Do
  192.              If RxFuncQuery('LoadLSRXUTFuncs')
  193.                Then Do
  194.                       Call RxFuncAdd 'LoadLsRxutFuncs', 'LSRXUT', 'LoadLsRxutFuncs'
  195.                       Call LoadLsRxutFuncs
  196.                     End
  197.                Else Nop
  198.           /* Say '* LSRXUT.DLL Version' LSRXUTVER() */
  199.            End
  200.       Else Do
  201.              Say '* Could not find' LSRDrive'\IBMLAN\NETLIB\LSRXUT.DLL' '07'x
  202.              Exit
  203.            End
  204.  
  205.     If Stream(LSRDrive'\ibmlan\netlib\wfrxutil.dll', 'C', 'Query Exists') <> ''
  206.       Then Do
  207.              Call RxFuncAdd 'WfrxLoadFuncs', 'WfrxUtil', 'WfrxLoadFuncs'
  208.              Call WfrxLoadFuncs
  209.            End
  210.       Else Do
  211.              Say '! Could not find' LSRDrive'\IBMLAN\NETLIB\WFRXUTIL.DLL' '07'x
  212.              Exit X2D('0800')
  213.            End
  214.  
  215.     If Stream(BootDrive'\os2\dll\rxutils.dll', 'C', 'Query Exists') <> ''
  216.       Then Do
  217.              If RxFuncQuery('RxLoadFuncs')
  218.                Then Do
  219.                       Call RxFuncAdd 'RxLoadFuncs', 'RXUTILS', 'RxLoadFuncs'
  220.                       Call RxLoadFuncs
  221.                     End
  222.                Else Nop
  223.           /* Say '* RXUTILS.DLL Version' RXUtilsVer() */
  224.              RXUtils = 1
  225.            End
  226.       Else Do
  227.              Say '! Could not find' BootDrive'\os2\dll\rxutils.dll'
  228.              RXUtils = 0
  229.            End
  230.  
  231.     Return
  232.  
  233.  CHKERROR:/* ----------------------------------------------------------------*/
  234.  
  235.     Parse Arg ErrorInformation
  236.  
  237.     Say '07'x
  238.     Call Logit ErrorInformation
  239.  
  240.     Exit
  241.  
  242.  LOGIT:/* -------------------------------------------------------------------*/
  243.  
  244.     Parse Arg LogText
  245.  
  246.     If Left(LogText, 1) = '!'
  247.       Then Nop
  248.       Else LogText = '-' LogText
  249.  
  250.     Say LogText
  251.     LogText = Date('E') Time() LogText
  252.  
  253.     If LineOut(LogFileName, LogText) = 0
  254.       Then Nop
  255.       Else Say '! Error while writing to the log file' '07'x
  256.     Call Stream LogFileName, 'C', 'Close'
  257.  
  258.     Return
  259.  
  260.