My company has a network of 146 AS/400s across the country all connected by satellite. Hundreds of PCs are attached to these AS/400s, and supporting them can be a nightmare. When a user calls in with a problem, whether he's a computer illiterate or a computer hacker, the help desk is often faced with a tedious task. You may be familiar with frustrating conversations similar to the one in 1.
My company has a network of 146 AS/400s across the country all connected by satellite. Hundreds of PCs are attached to these AS/400s, and supporting them can be a nightmare. When a user calls in with a problem, whether he's a computer illiterate or a computer hacker, the help desk is often faced with a tedious task. You may be familiar with frustrating conversations similar to the one in Figure 1.
We needed a way to obtain direct control of the PC remotely. We tried software packages like PC Anywhere and Carbon Copy. They are fine products, but they require modems (at both ends), and the PCs need to be near a phone line, which is not always possible. Also, with PC Support and the communication software package loaded on the remote PCs, we sometimes experienced memory problems. So I developed a utility that I call Run Remote PC Command (RUNRMTPCC). This utility allows us to control any PC attached to an AS/400 on our network and perform many DOS functions?such as displaying or copying files?without user intervention.
With this command, our support desk can pass DOS commands from an AS/400 interactive session to the target PC system and analyze problems directly. If the problem is with a file (such as CONFIG.SYS or AUTOEXEC.BAT), the file can be viewed from any AS/400 session. If necessary, the file can be copied to a shared folder and transferred through SNADS to another AS/400, where it can be changed and sent back.
Obviously, this process isn't fast. It also has some other limitations, most obviously that only one PC can use this program at a time. Even if you're using multiple AS/400 sessions, unpredictable results will occur if you attempt to manage or view data from more than one PC. But if you have ever been involved in a conversation like the one illustrated in 1, you won't really mind!
Obviously, this process isn't fast. It also has some other limitations, most obviously that only one PC can use this program at a time. Even if you're using multiple AS/400 sessions, unpredictable results will occur if you attempt to manage or view data from more than one PC. But if you have ever been involved in a conversation like the one illustrated in Figure 1, you won't really mind!
The Setup
The setup requires a PC connected to the AS/400 through PC Support or Client Access, and the shared folders function must be active. The remote PC must have QBASIC.EXE installed. (Generally, if the PC has DOS installed, it should have QBASIC.EXE in the DOS directory.)
These are the setup steps required on the AS/400:
1. Create folder RMTPCCFL with the Create Folder (CRTFLR) command and specify *CHANGE authority.
CRTFLR FLR(RMTPCCFL) AUT(*CHANGE)
2. Create the AS/400 source members in Figures 2-8. Compile the programs and files according to the compile instructions given at the beginning of each source member, substituting a library name where you see XXX.
3. Copy the BASIC program (CMDSRVR.BAS in 9 on page 96) and the batch file (CMDSRVR.BAT in 10 on page 96) to the RMTPCCFL shared folder you created in the first step. For example, COPY C:CMDSRV.BAS I:RMTPCCFL. (The copy of these files in shared folder RMTPCCFL will be used later to copy these files to any target PC on your network.)
3. Copy the BASIC program (CMDSRVR.BAS in Figure 9 on page 96) and the batch file (CMDSRVR.BAT in Figure 10 on page 96) to the RMTPCCFL shared folder you created in the first step. For example, COPY C:CMDSRV.BAS I:RMTPCCFL. (The copy of these files in shared folder RMTPCCFL will be used later to copy these files to any target PC on your network.)
These are the setup steps required on the remote PC:
1. Be sure that the PC contains the QBASIC.EXE file.
2. Copy the BASIC program, CMDSRVR.BAS, to the remote PC's PCS directory. (The easiest method might be to copy CMDSRVR.BAS from the RMTPCCFL shared folder.)
3. Copy the batch file, CMDSRVR.BAT to the remote PC's PCS directory. (Again, copying this file from the shared folder, RMTPCCFL, may be the easiest way to accomplish this.) The CMDSRVR.BAT file assumes that your QBASIC.EXE file is in the DOS directory on
the C drive and that CMDSRVR.BAS file is in your PCSdirectory on drive C. You may need to change these values.
Using RUNRMTPCC
To activate RUNRMTPCC, ensure that the shared folders function is active on the remote PC and have the user type CMDSRVR. This will start the command server program running on the PC. That's the only thing the remote user needs to do.
On the AS/400, key in the RUNRMTPCC command. The Run Remote PC Command panel appears. Enter the DOS command that you want the remote PC to execute. The command will be transmitted to the PC and executed. Any command results that are normally displayed on the PC will be displayed on your AS/400 screen.
When you are done viewing information from a PC command, press Enter, F12, or F3 to redisplay the Run Remote PC Command panel. If you want to end the command server program (CMDSRVR.BAT) on the PC from the AS/400, press F15. If you want to end the CMDSRVR.BAT program from the remote PC, have the remote user press any key. The user will be prompted to enter C to cancel. If the user enters C or c, the program will end. If you want to exit the RUNRMTPCC command, but leave the PC server program running, just press F3. You can then restart the RUNRMTPCC command without requiring the remote user to rerun the CMDSRVR program. To end both the server and the client portion of this command, press F15 followed by F3.
If you have entered a DOS command and you don't get a response from the PC after a long time, you can press the Attn key to cancel RUNRMTPCC.
How It Works
RUNRMTPCC works by using the shared folder facility of PC Support. On the AS/400 side, the DOS command you want to run on the remote PC is written to a database file and then copied to a PC file in shared folder RMTPCCFL. The BASIC program, CMDSRV.BAS, running on the remote PC, picks up the DOS command, executes it, and sends back the results through another PC file in the RMTPCCFL shared folder, which is copied to an AS/400 database file. The output from the PC is now contained in an AS/400 file, which is displayed using the Display Physical File Member (DSPPFM) command on the AS/400.
If you want more detail on how this utilility works, read on. When you enter a command, it is written to the AS/400 file PCOUT. The CL program CMD011CL (6) copies the AS/400 file PCOUT to a PC file called PCOUT.CMD in the RMTPCCFL shared folder. The BASIC program running on the PC, CMDSRVR (9), checks every ten seconds to see if the PCOUT.CMD file exists. When it detects the file, it reads the contents (the DOS command keyed at the AS/400) and executes the command with the DOS SHELL command. The output of the DOS command is piped to the results file, PCIN.TXT in the RMTPCCFL folder. The CL program CMD012CL (7) attempts to copy the PC file PCIN.TXT to an AS/400 database file every ten seconds. When it is successful, it returns to the RPG program, CMD010RG (5), which opens the file and displays the contents through the DSPPFM command.
If you want more detail on how this utilility works, read on. When you enter a command, it is written to the AS/400 file PCOUT. The CL program CMD011CL (Figure 6) copies the AS/400 file PCOUT to a PC file called PCOUT.CMD in the RMTPCCFL shared folder. The BASIC program running on the PC, CMDSRVR (Figure 9), checks every ten seconds to see if the PCOUT.CMD file exists. When it detects the file, it reads the contents (the DOS command keyed at the AS/400) and executes the command with the DOS SHELL command. The output of the DOS command is piped to the results file, PCIN.TXT in the RMTPCCFL folder. The CL program CMD012CL (Figure 7) attempts to copy the PC file PCIN.TXT to an AS/400 database file every ten seconds. When it is successful, it returns to the RPG program, CMD010RG (Figure 5), which opens the file and displays the contents through the DSPPFM command.
If the AS/400 user presses the Attn key, the CL program CMD013CL (8) is called, which sends an entry to the data queue RMTPCCDQ. This makes program CMD012CL end the wait and send back a code to the RPG program that causes it to end.
If the AS/400 user presses the Attn key, the CL program CMD013CL (Figure 8) is called, which sends an entry to the data queue RMTPCCDQ. This makes program CMD012CL end the wait and send back a code to the RPG program that causes it to end.
If the user presses F15, a special entry is written to the PCOUT file. This entry is read by the CMDSRVR program on the PC, causing it to end.
Some Things to Consider
If you're running Client Access for Windows 3.1, you need to change the two statements labeled A in the CMDSRVR.BAS program in 9 to comments. Insert a single quote at the beginning of each statement. Next, you need to change the two comment statements labeled B in the CMDSRVR.BAS program by removing the single quote at the beginning of each statement.
If you're running Client Access for Windows 3.1, you need to change the two statements labeled A in the CMDSRVR.BAS program in Figure 9 to comments. Insert a single quote at the beginning of each statement. Next, you need to change the two comment statements labeled B in the CMDSRVR.BAS program by removing the single quote at the beginning of each statement.
The change is required because shared folders under Client Access for Windows are no longer stored in the root directory; instead, they are stored as subdirectories under the QDLS directory.
This utility does have limitations of which you should be aware. For instance, it can't run any interactive applications on the remote PC. Using the DOS command parameter /P (pause) with DOS commands such as DIR or piping output of certain DOS commands may cause the remote PC to pause. In this case, the remote user will need to press any key to continue.
The RUNRMTPCC command doesn't check to see how many remote PCs are running the CMDSRVR program. If more than one remote PC happens to be running the CMDSRVR program, it would be difficult to predict which PC would actually process the command you enter from the AS/400.
Help for Your Help Desk
There are many more-sophisticated solutions to supporting remote PCs. For example, you could set up a LAN with a Network Operating System (NOS) and easily gain access to remote PCs. However, if you're not using a NOS and you're using PC Support or Client Access, the RUNRMTPCC command may provide all you need to offer basic support to your remote PCs. It gets the job done for us here.
Albert York is the manager of Systems Development for the Infinitinet Division at Nissan. He has been a S/38 and AS/400 consultant since 1981.
The Run Remote PC Command Utility
Figure 1: A Conversation with a Remote PC User
Support desk (SD): Now type TYPE CONFIG.SYS and tell me what it says. User (U): It says Bad Command Or File Name. SD: Tell me what you typed. U: I typed CONFIGDOTSYS just like you said. SD: No. Let me spell it out. Type T-Y-P-E-space-C-O-N-F-I-G-period-S-Y-S. U: Okay. Now we have a bunch of stuff on the screen. SD: Please read it to me. U: R-E-M-space-C-O-N-F-I-G-period-S-Y-S-space-C-O-N-F-I-G-U-R-A-T-I-O-N...
The Run Remote PC Command Utility
Figure 2: The RUNRMTPCC Command Source
/*==================================================================*/ /* To compile: */ /* */ /* CRTCMD CMD(XXX/RUNRMTPCC) PGM(XXX/CMD010CL) + */ /* SRCFILE(XXX/QCMDSRC) */ /* */ /*==================================================================*/ CMD PROMPT('Run Remote PC Command')
The Run Remote PC Command Utility
Figure 3: CPP CL Program CMD010CL
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/CMD010CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ CMD010CL: PGM CHKOBJ OBJ(QGPL/PCIN) OBJTYPE(*FILE) MONMSG MSGID(CPF9801) EXEC(CRTPF FILE(QGPL/PCIN) + RCDLEN(512)) CHKOBJ OBJ(QGPL/PCOUT) OBJTYPE(*FILE) MONMSG MSGID(CPF9801) EXEC(CRTPF FILE(QGPL/PCOUT) + RCDLEN(138)) CHKOBJ OBJ(QGPL/RMTPCCDQ) OBJTYPE(*DTAQ) MONMSG MSGID(CPF9801) EXEC(CRTDTAQ + DTAQ(QGPL/RMTPCCDQ) MAXLEN(1)) /* CLEAR FILES FROM PRIOR RUN */ CLRPFM FILE(PCOUT) DLTDLO DLO(PCOUT.CMD) FLR(RMTPCCFL) MONMSG MSGID(CPF0000) CALL PGM(QCLRDTAQ) PARM('RMTPCCDQ' 'QGPL') /* SET ATTN KEY TO ALLOW USER TO CANCEL WAIT FOR RESPONSE FROM PC */ SETATNPGM PGM(CMD013CL) SET(*ON) /* EXECUTE PROGRAM */ CALL PGM(CMD010RG) ENDPGM: ENDPGM
The Run Remote PC Command Utility
Figure 4: Display File CMD010DF
*=============================================================== * To compile: * * CRTDSPF FILE(XXX/CMD010DF) SRCFILE(XXX/QDDSSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 A DSPSIZ(24 80 *DS3) A CA03(03) A CA12(03) A CA15(15) A R CMDFMT A 1 30'Run Remote PC Command' A DSPATR(HI) A 3 1'Command to execute:' A DSPATR(HI) A WSCMD 138A B 3 22 A 23 1'F3=Exit F15=End PC pgm' A COLOR(BLU) A R SENDMSG A OVERLAY A CLRL(01) A FRCDTA A 24 2'Sending command to remote PC ...' A DSPATR(HI) A R WAITMSG A OVERLAY A CLRL(01) A FRCDTA A 24 2'Waiting for response from remote P- A C. Press ATTN to cancel ...' A DSPATR(HI)
The Run Remote PC Command Utility
Figure 5: RPG Program CMD010RG
*=============================================================== * To compile: * * CRTRPGPGM PGM(XXX/CMD010RG) SRCFILE(XXX/QRPGSRC) * *=============================================================== *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 FCMD010DFCF E WORKSTN FPCOUT O F 138 DISK UC * * I 'DSPPFM QGPL/PCIN' C CMD * C *IN03 DOWEQ*OFF * C EXFMTCMDFMT C *IN03 IFEQ *OFF * * F15 - END PC PROGRAM C *IN15 IFEQ *ON C MOVEL'%%END%%' WSCMD P C EXSR WRTCMD C MOVE *BLANKS WSCMD C ITER C ENDIF * * DISPLAY MESSAGE AND SEND COMMAND TO THE PC C WRITESENDMSG C EXSR WRTCMD * * WAIT FOR RESPONSE. ALLOW USER TO CANCEL BY PRESSING ATTN C WRITEWAITMSG C CALL 'CMD012CL' C PARM '0' RESULT 1 * USER CANCELED - REDISPLAY C RESULT IFEQ '0' C CALL 'QCMDEXC' C PARM CMD CMDSTR 16 C PARM 16 CMDLEN 155 C ENDIF * C ENDIF * C ENDDO * C MOVE *ON *INLR * WRITE COMMAND TO PCCMD FILE AND SEND IT TO THE PC * C WRTCMD BEGSR C OPEN PCOUT C EXCPT C CLOSEPCOUT C MOVE *BLANKS WSCMD C CALL 'CMD011CL' C ENDSR * OPCOUT E O WSCMD *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7
The Run Remote PC Command Utility
Figure 6: CL Program CMD011CL
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/CMD011CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ CMD011CL: PGM /* Delete PC response file */ DLTDLO DLO(PCIN.TXT) FLR(RMTPCCFL) MONMSG MSGID(CPF0000) /* Copy AS/400 file containing PC command to PC file */ CPYTOPCD FROMFILE(PCOUT) TOFLR(RMTPCCFL) + TODOC(PCOUT.CMD) REPLACE(*YES) /* Clear AS/400 PC command file */ CLRPFM FILE(PCOUT) ENDPGM: ENDPGM
The Run Remote PC Command Utility
Figure 7: CL Program CMD012CL
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/CMD012CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ CMD012CL: PGM PARM(&RESULT) DCL VAR(&RESULT) TYPE(*CHAR) LEN(1) DCL VAR(&LENGTH) TYPE(*DEC) LEN(5 0) DCL VAR(&DQDATA) TYPE(*CHAR) LEN(1) DCL VAR(&WAIT) TYPE(*DEC) LEN(5 0) VALUE(10) /* Clear data queue */ CALL PGM(QCLRDTAQ) PARM(RMTPCCDQ 'QGPL') /* Wait for response from PC + Check for existance of PC file every 10 seconds + If user presses Attn key, an entry is sent to the data queue */ WAIT: CALL PGM(QRCVDTAQ) PARM('RMTPCCDQ' '*LIBL' &LENGTH + &DQDATA &WAIT) /* User cancelled wait */ IF COND(&LENGTH *NE 0) THEN(DO) CHGVAR VAR(&RESULT) VALUE('1') RETURN ENDDO /* Attempt to copy PC response to AS/400 file */ CPYFRMPCD FROMFLR(RMTPCCFL) TOFILE(PCIN) + FROMDOC(PCIN.TXT) /* Error, continue waiting */ MONMSG MSGID(CPF0000 IWS0000) EXEC(GOTO CMDLBL(WAIT)) ENDPGM: ENDPGM
The Run Remote PC Command Utility
Figure 8: CL Program CMD013CL
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/CMD013CL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ CMD013CL: PGM DCL VAR(&DQLEN) TYPE(*DEC) LEN(5 0) VALUE(1) /* Send entry to data queue */ CALL PGM(QSNDDTAQ) PARM('RMTPCCDQ' 'QGPL' &DQLEN + 'C') ENDPGM: ENDPGM
The Run Remote PC Command Utility
Figure 9: PC Command Server Program CMDSRVR.BAS
' CMDSRVR.BAS ' BASIC program to execute DOS commands entered on the AS/400 ' Setup DEFINT A-Z CLS PRINT "Starting PC command executor" ' The following two statements are for ' PC Support and Client Access DOSclients (standard or extended) CommandFile$ = "I:RMTPCCFLPCOUT.CMD" ResultFile$ = "I:RMTPCCFLPCIN.TXT" ' The following two statements are for the ' Client Access Windows 3.1 client ' CommandFile$ = "I:QDLSRMTPCCFLPCOUT.CMD" ' ResultFile$ = "I:QDLSRMTPCCFLPCIN.TXT" True = -1: False = 0 ON ERROR GOTO ErrorRoutine ' Start of main loop WaitForCommand: time1& = TIMER ' Allow PC user to cancel program by pressing a key CheckKeyBoard: KeyboardChar$ = INKEY$ IF KeyboardChar$ = "" THEN GOTO CheckTime PRINT INPUT "Enter C to cancel ", KeyboardChar$ IF KeyboardChar$ = "C" OR KeyboardChar$ = "c" THEN SYSTEM ' Check every 10 seconds CheckTime: IF TIMER - time1& < 10 THEN GOTO CheckKeyBoard CheckCommandFile: ' Look for PCOUT.CMD file ErrorOccurred = False OPEN CommandFile$ FOR INPUT AS #1 ' File does not exist. No command has been entered. IF ErrorOccurred THEN GOTO WaitForCommand ' Read the file to get the command LINE INPUT #1, CommandString$ CLOSE #1 ' Delete the file KILL CommandFile$ CommandString$ = RTRIM$(CommandString$) ' Special command to end this program IF CommandString$ = "%%END%%" THEN SYSTEM CLS PRINT "Executing: "; CommandString$ ' Save the row number that the cursor is currently on SaveRow = CSRLIN ' Create a DOS command ShellCommand$ = CommandString$ + " > " + ResultFile$ ' Execute the DOS command SHELL ShellCommand$ ' Check the result file ErrorOccurred = False OPEN ResultFile$ FOR INPUT AS #2 ' No results generated IF ErrorOccurred THEN GOTO CreateResultFile ' Find number of characters in file FileSize% = LOF(2) CLOSE #2 IF FileSize% > 0 THEN GOTO CommandCompleted ' File is empty KILL ResultFile$ ' Results may have been displayed to the screen. Read the screen and ' copy the contents to the result file. CreateResultFile: OPEN ResultFile$ FOR OUTPUT AS #2 NoOutput = True CurrentRow = CSRLIN ' Process one row at a time, starting where the cursor was before the command ' was executed FOR Row = SaveRow TO CurrentRow TextLine$ = "" CharacterWasFound = False FOR Column = 1 TO 80 ScreenChar$ = CHR$(SCREEN(Row, Column)) TextLine$ = TextLine$ + ScreenChar$ IF ScreenChar$ > " " THEN CharacterWasFound = True NEXT IF CharacterWasFound THEN PRINT #2, TextLine$ NoOutput = False END IF NEXT ' No output generated at all. IF NoOutput THEN PRINT #2, "Command execution complete. No output generated." END IF CLOSE #2 CommandCompleted: PRINT "Complete" GOTO WaitForCommand ' General error handling routine ErrorRoutine: ErrorOccurred = True RESUME NEXT
The Run Remote PC Command Utility
Figure 10: PC Batch File CMDSRVR.BAT
C:DOSQBASIC.EXE /RUN C:PCSCMDSRVR.BAS
LATEST COMMENTS
MC Press Online