Windows»Automatically logoff users at …
  • RSS Feed

Last modified on 9/28/2017 2:08 PM by User.

Tags:

Automatically logoff users at night

This only works on Windows servers.  Not Unix.

Profits Plus needs to sort and manipulate certain files at night but can't do that if a user has left their terminal in a program that has one of those files open.  This logoff feature is intended to identify the users who are still running programs at night that might interfere with the night processing sorting task and log them off of Windows.  This has the following effect:

  • The Profits Plus programs being run by a logged off user will be ended. 
  • The file locks held by that program will be cleared.
  • Profits Plus night processing that runs later will be able to sort/maintain the files.

It only logs off users who are running Profits Plus programs that might interfere with Profits Plus night processing.  

  • Users who are in the Profits Plus menu, will not get logged off.  
  • Users who are logged into Windows but not running Profits Plus will not be logged off.

This works for both local and remote desktop connections (RDP).

 

Installation procedures

  • Install these files from the MVS Unix server.
    • win32\bin\night_logoff.bat 
    • dsk0\002002\night_logoff_common.bat
    • dsk2\100000\logoff.run
  • Configure win32\bin\night_logoff.bat (see below in the appendix)
  • Add a scheduled task to run win32\bin\night_logoff.bat 15 minutes before win32\bin\night_win32.bat runs.
    • Each night this creates a new %MVS_ROOT\logoff.log that shows who got logged off.

Appendix

Configure win32\bin\night_logoff.bat

This is the only .bat file that you will need to modify for the logoff feature.

Search for the string @Configure in night_logoff.bat to find the 3 lines that need to be configured for the customer's environment.  Each line you need to change is not commented out with the :: symbols  but it will be surrounded by comment lines (::) trying to explain what to do. 

1. Path to win32\env\setup_env.bat

The default is C:\u\mvs\win32\env\setup_env.bat .   Change the path only if MVS_ROOT is not C:\u\mvs

2. NIGHT_TAG environment variable 

You should normally leave this set to blank.  SET NIGHT_TAG=

You only need to set a value if you need to run a separate logoff scheduled task for only certain companies at different parts of the day on the same Profits Plus server.  This is totally optional, unusual and you will probably never have to do this.

For example RGS has: 

  • A Las Vegas company 1 that runs a win32\bin\night_win32.bat at 11:00pm
    • In win32\bin\night_logoff.bat set the NIGHT_TAG= blank  and INI'COMPANIES=1
    • Add a scheduled task to run win32\bin\night_logoff.bat at 10:45pm 
    • It will create a log in %MVS_ROOT%\logoff.log
    • The Singapore company 3 will not be affected
  • A Singapore company 3 that runs win32\bin\night_win32_sg.bat at 4:00pm.
    • Copy win32\bin\night_logoff.bat to win32\bin\night_logoff_sg.bat
    • In win32\bin\night_logoff_sg.bat set the NIGHT_TAG=_sg  and INI'COMPANIES=3
    • Add a scheduled task to run win32\bin\night_logoff_sg.bat at 3:45pm 
    • It will create a log in %MVS_ROOT%\logoff_sg.log
    • The Las Vegas company 1 will not be affected.
    • The same dsk0\002002\night_logoff_common.bat will be used for this instance of logoff

3. INI'COMPANIES=??

These are decimal company numbers, not octal.  They should match the company numbers shown in the stack inquiry screen.  The default is set to 99 so if you accidentally run the .bat file by clicking on it, it won't affect anything, but when you set this to a real company be careful because it will logoff Windows users immediately just by double clicking on the .bat file. 

Multiple company numbers should be delimited by a +.  Example:   INI'COMPANIES=1+2+10

 

 

win32\bin\night_logoff.bat

@ECHO OFF
::************************************************************************
::
:: ----  M V S   P R O G R A M   S O U R C E   M O D U L E  ----
:: (C) Copyright 1989 by M.V. Software Company, Inc.
::
:: Purpose: logoff Windows users before Profits Plus night processing
::
:: Output:  %MVS_ROOT%\logoff.log   a log of who got logged off
:: 
:: Search for @Configure for lines you need to change for each customer.
::
:: ---------------------------------------------------------------------
::
::  NOTE: - Windows requires that this be run by administrator.  
::        - The DOS logoff command will get "access denied" errors for
::          anyone other than administator. 
::        - Being part of the administrators group isn't enough.
::        - Having administrator privileges isn't enough.
::        - You must logon as administrator.
::        - The scheduled task must be given the administrator 
::          credentials.
::        - You can also test it by right clicking on this bat and 
::          choosng "Run as administrator".
::
::        - That is why it is a separate scheduled task, 
::          normal night processing isn't run by administrator.
::
:: ---------------------------------------------------------------------
::
::
:: %MVS_ROOT%\win32\bin\night_logoff.bat     
::                                           
:: Created - 07/17
:: Revised - 
::
:: See also:  dsk1\100077\logoff.psm   executes the DOS logoff commands
::            dsk0\002002\night_logoff_common.bat common logoff logic
::
::************************************************************************
 
:: ----------------------------------------------------------
:: ------------------ @Configure ----------------------------
:: ----------------------------------------------------------
:: Since this is launched from a scheduled task
:: we can't use the %MVS_ROOT% environment variable at
:: this point because it hasn't been set yet.  You must 
:: change the line below to the correct path to the 
:: customer's win32\env\setup_env.bat 
CALL C:\u\mvs\win32\env\setup_env.bat
:: ----------------------------------------------------------
 
%MVS_DRIVE%:
cd %MVS_ROOT_ND%
 
:: ----------------------------------------------------------
:: ------------------ @Configure ----------------------------
:: ----------------------------------------------------------
:: Set a tag value that can be used to distinguish between 
:: different instances of this script.  It will be used
:: to create a separate log for each instance.
:: Each NIGHT_TAG will require a separate version of this
:: script in win32\bin.
:: ----------------------------------------------------------
::                       Creates         This .bat filename
:: NIGHT_TAG  instance   %MVS_ROOT% log  in win32/bin
:: ---------  ---------  --------------  --------------------
::            default    logout.log      night_logoff.bat
::    _sg     Singapore  logout_sg.log   night_logoff_sg.bat
::
:: Remove trailing spaces from the value!
SET NIGHT_TAG=
:: ----------------------------------------------------------
 
SET TRASH=%MVS_ROOT_ND%\dsk0\100001\trash
:: ----------------------------------------------------------
:: Tell logoff.psm the name of the parameter file 
:: we will create below so it knows what to do.
SET INI_FILENAME=%TRASH%\lgo.parms.ini
:: ----------------------------------------------------------
 
 
:: ----------------------------------------------------------
:: There are 2 logs defined here.
:: ----------------------------------------------------------
:: LOGFNAME is the main log for the batch files.
:: It is the one you'll see in %MVS_ROOT%\logoff.log
 
SET LOGFNAME=%MVS_ROOT%\logoff%NIGHT_TAG%.log
 
:: LOGOFF_LOG_FNAME is only for the logoff.psm program.
:: The night_logoff_common.bat will merge the 2 logs 
:: after logoff.psm ends.
 
SET LOGOFF_LOG_FNAME=%TRASH%\lgo.logoff%NIGHT_TAG%.log
IF EXIST %LOGOFF_LOG_FNAME% DEL %LOGOFF_LOG_FNAME%
:: ----------------------------------------------------------
 
:: ----------------------------------------------------------
:: Start a new parameter file for logoff.psm
:: ----------------------------------------------------------
 
:: ----------------------------------------------------------
:: ------------------ @Configure ----------------------------
:: ----------------------------------------------------------
:: This tells logoff.psm which companies to logoff.
:: They will be matched to the company # in stack inquiry.
:: These are decimal (not octal) numbers.
:: No leading zeros.
:: Only users running programs in one of these
:: companies will be logged off. 
:: Multiple COMPANIES must be delimited by +
:: example:  INI'COMPANIES=1+2+10 
:: example:  INI'COMPANIES=1
:: example:  INI'COMPANIES=ALL
:: blank or ALL means ALL companies
echo INI'COMPANIES=99 > %INI_FILENAME%
:: ----------------------------------------------------------
 
echo INI'LOG'FNAME=%LOGOFF_LOG_FNAME% >> %INI_FILENAME%
:: night_logoff_common.bat will add more paramters 
:: to %INI_FILENAME% later
 
:: ----------------------------------------------------------
:: Log the current environment variables
:: ----------------------------------------------------------
echo %DATE% %TIME% > %LOGFNAME%
echo night_logoff%NIGHT_TAG%.bat:100: >> %LOGFNAME%
echo MVS_DRIVE=%MVS_DRIVE% >> %LOGFNAME% 
echo MVS_ROOT_ND=%MVS_ROOT_ND% >> %LOGFNAME%
echo TMPDIR=%TMPDIR% >> %LOGFNAME%
echo MVS_PLATFORM=%MVS_PLATFORM% >> %LOGFNAME%
echo PATH=%PATH% >> %LOGFNAME%
 
cd %MVS_ROOT_ND%\dsk0\100001
:: ----------------------------------------------------------
::   night_logoff_common.bat is in dsk0/002002
::   and is the same for all companies and users.
::   It will actually do the logging off.
::   We launch a separate batch file here so all of the
::   standard out text can be redirected to the main 
::   log file.
:: ----------------------------------------------------------
CALL night_logoff_common.bat >> %LOGFNAME% 2>&1
::
echo night_logoff%NIGHT_TAG%.bat:complete: >> %LOGFNAME%
echo %DATE% %TIME% >> %LOGFNAME%
exit
:: ********** End of file     **********
 

dsk0\002002\night_logoff_common.bat

@ECHO OFF
::************************************************************************
::
:: ----  M V S   P R O G R A M   S O U R C E   M O D U L E  ----
:: (C) Copyright 1989 by M.V. Software Company, Inc.
::
:: %MVS_ROOT%\dsk0\002002\night_logoff_common.bat     
::   - MVS nightly process script
::   - Called from %MVS_ROOT%\win32\bin\night_logoff.bat via scheduled task
::   - This scheduled task should occur shortly before the normal night processing
::     script win32\bin\night_win32.bat  
::   - Automatically logoff users who are running programs that might 
::     interfere with night processing later on.
::   - The caller should redirect our standard out to a log file, ie: 2>&1
::
:: Parameters: %INI_FILENAME% = env variable with path/filename of parms file
::                            for logoff.run program.
::                            Don't overwrite this file, you can add new 
::                            records but don't erase existing ones.
::             %TRASH% = env variable with path to dsk0\100001\trash folder
::             %NIGHT_TAG% = env variable string appended to filenames 
::                           to distinquish different contexts.  
::                           example: NIGHT_TAG=_sg  for Singapore 
::                                    NIGHT_TAG=_lv  for Las Vegas  
::             %LOGOFF_LOG_FNAME% = the log file for logoff.psm only.  
::                                  It is different than the main log 
::                                  and will be merged into the main log
::                                  after logoff.psm ends.
::                                   
:: Created - 07/17
:: Revised - 
:: 
::************************************************************************
echo night_logoff_common.bat:100: 
 
:: Setup variables specific to night processing by platform
CALL %MVS_ROOT%\%MVS_PLATFORM%\env\night_env.bat
echo night_logoff_common.bat:120: 
 
:: Tell all Softworks Basic programs they are running from the command line.
:: Makes the logout.out log cleaner.
:: Q=Quiet, N=No common
SET GLOBAL_RUN_MODE=QN      
 
 
SET JOBNUMBER=998
echo JOBNUMBER=%JOBNUMBER%
echo MVS_ROOT=%MVS_ROOT%
echo MVS_RUN=%MVS_RUN%
echo MVS_DRIVE=%MVS_DRIVE%
echo MVS_PLATFORM=%MVS_PLATFORM%
echo PATH=%PATH%
echo TRASH=%TRASH% 
echo NIGHT_TAG=%NIGHT_TAG% 
echo INI_FILENAME=%INI_FILENAME% 
 
:: Abort if the INI_FILENAME variable isn't set
IF NOT "%INI_FILENAME%" == "" GOTO STKLST_DO
echo night_logoff_common.bat:150: 
ECHO **** ERROR: INI_FILENAME variable not set! *****
GOTO END_BAT
 
 
:STKLST_DO
 
::************************************************************************
:: stklst.run creates a text file "stklst.prt" containing a list of
:: usernames that are still running programs. It also shows the company #
:: they are using.  logoff.run will read this file.
echo night_logoff_common.bat:200: 
SET GLOBAL_RUN_MODE=QN
SET STKLST_FNAME=%MVS_ROOT_ND%\dsk0\100001\stklst.prt
echo STKLST_FNAME=%STKLST_FNAME%
IF EXIST %STKLST_FNAME% DEL %STKLST_FNAME%
cd %MVS_ROOT_ND%\dsk0\100001
CALL %MVS_RUN% %MVS_ROOT_ND%\dsk2\100000\stklst.run
IF EXIST %STKLST_FNAME% GOTO STKLST_OK
echo night_logoff_common.bat:220: 
echo stklst.run failed. %STKLST_FNAME% not found
GOTO END_BAT
 
:STKLST_OK
:: add the stklst.prt file to the log for easy troubleshooting
echo ---------------------------------------------------------------------------
echo                     S T A C K     I N Q U I R Y         STKLST.PRT
echo ----.----1----.----2----.----3----.----4----.----5----.----6----.----7----.
type %STKLST_FNAME%
::
::     These users were still running programs that may affect night processing:
::  
::   USER         TERM   MINUTES   CO.  CURRENT PROGRAM
::   s.repro.mv     5   1.7 days    3   ORDENT[250,0]:DSK02                      
::   maureen.mv    11   5.9  hrs    3   GLAMNT[230,000]:DSK02                    
::   s.reception.  13   1.4 days    3   ORDENT[250,000]:DSK02                    
::   s.paresh.mv   19   1.5 days    3   SELECT.RUN[220,000]:DSK02                
::   ==========================================================================
 
:SESSION_DO
:: Create a text file of usernames and session id.  logoff.run reads this
echo night_logoff_common.bat:300: 
 
SET SESSION_FNAME=%TRASH%\lgo.session.users
echo SESSION_FNAME=%SESSION_FNAME%
IF EXIST %SESSION_FNAME% DEL %SESSION_FNAME%
query session > %SESSION_FNAME%
 
echo night_logoff_common.bat:310: 
 
IF EXIST %SESSION_FNAME% GOTO SESSION_OK
echo night_logoff_common.bat:320: 
GOTO END_BAT
 
:SESSION_OK
:: add the session log to the log for easy troubleshooting
echo ---------------------------------------------------------------------------
echo                    U S E R     S E S S I O N     I D
echo ----.----1----.----2----.----3----.----4----.----5----.----6----.----7----.
type %SESSION_FNAME%
::    SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE 
::    services                                    0  Disc                        
::    console           administrator             1  Active                      
::                      maureen.mv                2  Disc                        
::    rdp-tcp#0         fedex.mv                  3  Active  rdpwd               
::    rdp-tcp#1         billy.mv                  4  Active  rdpwd               
::    rdp-tcp#2         ereception.mv             5  Active  rdpwd               
::    rdp-tcp#3         Eastern.mv                6  Active  rdpwd               
::    rdp-tcp#4         jeryl.mv                  7  Active  rdpwd               
::    rdp-tcp#5         ap.mv                     8  Active  rdpwd               
::   >rdp-tcp#6         mvlogin.mv                9  Active  rdpwd               
::    rdp-tcp                                 65536  Listen                      
 
:LOGOFF_DO
echo night_logoff_common.bat:400: 
echo -----------------------------------------
echo             L O G O F F 
echo -----------------------------------------
:: name a success flag file that logoff.run will
:: create if it is successful.  We'll check it later.
:: Add that filename to logoff.run's parm file.
SET OK_FNAME=%TRASH%\lgo.ok.flag
IF EXIST %OK_FNAME% DEL %OK_FNAME%
echo INI'OK'FNAME=%OK_FNAME% >> %INI_FILENAME%
echo INI'SESSION'FNAME=%SESSION_FNAME% >> %INI_FILENAME%
echo INI'MY'LOGIN=%LOGNAME% >> %INI_FILENAME%
::
echo INI'STKLST'FNAME=%STKLST_FNAME%  >> %INI_FILENAME%
:: logoff.run reads the STKLST_FNAME file
::   for every user that is running in the specified companies
::      - find that user in the SESSION_FNAME file to get the it's session ID
::      - execute a DOS command line "logoff ID" to logoff that user.
::      - example:  logoff 2
::                  (logs off maureen.mv)    
SET GLOBAL_RUN_MODE=QN 
cd %MVS_ROOT_ND%\dsk0\100001
CALL %MVS_RUN% "DSK2:LOGOFF.RUN[100,000]"
 
echo night_logoff_common.bat:420: 
:: Careful:  there are 2 logs.  1 log for logoff.run below and a 2nd log for
::           the main batch file launched from win32/bin.
::           When all this if finished there will be just one main log that
::           contains both logs.
::           LOGOFF_LOG_FNAME was set by the .bat file that called us. 
:: Add the logoff.psm log to the main log.
IF EXIST %LOGOFF_LOG_FNAME% TYPE %LOGOFF_LOG_FNAME%
 
IF NOT EXIST %OK_FNAME% GOTO BAT_FAIL
GOTO BAT_OK
 
:BAT_FAIL
echo night_logoff_common.bat:490:  FAILURE
echo logoff.run failed. %OK_FNAME% not found
GOTO END_BAT
 
:BAT_OK
echo night_logoff_common.bat:complete:
 
:END_BAT
::
:: ********** End of file     **********
 

dsk2\100000\logoff.run 

This is on the mvs unix server at /u/mvs/dsk2/100000/logoff.run.