如何檢查使用者是否已經 Signed On 進入系統?(使用 API QUSLJOB)
方法一:
你可於使用者初始程式(Initial Program)中使用指令
CHGMSGQ MSGQ(*USRPRF) DLVRY(*BREAK)
MONMSG CPF2451 EXEC(DO)
SNDPGMMSG MSG('USER Already Signon') MSGTYPE(*COMP)
ENDDO
當監控到 MSGID CPF2451表示該使用者已經進入系統了,您接著可做後續處理,如強迫使用者
退出系統,除非使用者先結束前一個工作站作業,才能再開啟另一個工作站。
方法二:較彈性化的做法是使用 API QUSLJOB 判斷使用者已進入系統(SignOn)的次數,範例如下:
File : QCLSRC
Member: CHKACTUSRC
Type : CLP
Usage : CRTCLPGM CHKACTUSRC
ChkActUsr: pgm ( +
&pChkUsr +
&pNbrLstE +
)
dcl &pChkUsr *char 10
/* Number of list entries: Listed jobs... */
dcl &pNbrLstE *dec (7)
/*-----------------------------------------------------*/
dcl &usrspc *char 10 VALUE( '#$CHKUSRAC' )
dcl &usrspclib *char 10 VALUE( 'QTEMP ' )
dcl &qusrspc *char 20
dcl &us_hdr *char 150 /* Space header */
/* The qualified search job name... */
dcl &SchJob *char 26
monmsg cpf0000 exec(goto error_rtn)
/*-----------------------------------------------------*/
chgvar &qusrsp ( &usrspc *cat &usrspclib )
/* Create usrspc to hold objlck data from this usrprf */
call QUSCRTUS ( +
&qusrspc +
'TMPLST ' +
x'00001000' +
X'00' +
'*ALL ' +
'Temp list usr jobs ' +
'*YES ' +
x'0000000000000000' +
)
/* */
/* Populate usrspc with appropriate job list data... */
/* */
chgvar &SchJob ( +
'*ALL ' *cat +
&pChkUsr *cat +
'*ALL ' +
)
call QUSLJOB ( +
&qusrspc +
'JOBL0100' +
&SchJob +
'*ACTIVE ' +
x'0000000000000000' +
'I' +
x'00000000' +
x'00000000' +
)
/* Retrieve the header data... */
call QUSRTVUS ( +
&qusrspc +
x'00000001' +
x'00000096' +
&us_hdr +
)
chgvar &pNbrLstE %bin( &us_hdr 133 4 )
/*------------------------------------------------------*/
Clean_up:
dltusrspc &usrspclib/&usrspc
return
/*------------------------------------------------------*/
/* */
/* Unexpected error */
/* */
Error_rtn:
chgvar &pNbrLstE -1
monmsg (cpf0000 mch0000)
return
endpgm
File : QCLSRC
Member: CHKACTUSRT
Type : CLP
Usage : CRTCLPGM CHKACTUSRT
CALL CHKACTUSRT 'userprofile'
ChkActUsrt: pgm (&pChkUsr)
dcl &pChkUsr *char 10
/* Number of list entries: Listed jobs... */
dcl &pNbrLstE *dec (7)
dcl &pNbrLstEC *CHAR (7)
CALL chkactusrc (&pChkUsr &pNbrLstE)
CHGVAR &pNbrLstEC &pNbrLstE
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('User ' +
*CAT &pChkUsr *bcat 'signon' *BCAT &PNBRLSTEC *CAT ' times') +
TOPGMQ(*PRV) MSGTYPE(*COMP)
endpgm
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期四, 11月 02, 2023
2002-06-24 如何檢查使用者是否已經 Signed On 進入系統?(使用 API QUSLJOB)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言