May 26 2015

Run AS400 Session on Windows Startup

Published by at 11:23 pm under AS400

You may need to launch AS400 sessions at boot for various reasons such as automated scripts or print sessions. Here are a few pitfalls you may encounter.

First of all, sessions wouldn’t launch without pcsws.exe extra parameters /H – for Hidden – and eventually /Q – to hide the IBM popup window. pcsws.exe options are all listed on IBM for reference.

This will work for a single session. In order to deal with 2 or more sessions, they have to be launched with the “start” command. Add /B parameter to hide the DOS command window followed by “”, or the main command parameters will be being ignored.

This makes me come up with the following simple batch.

@echo off

Set ScriptPath=C:\Scripts
Set client_Access_Home=C:\Program Files (x86)\IBM\Client Access
Set AS400=My_iSeries_Host
Set iSeries_User=myUser
Set password=myPassword

"%client_Access_Home%\cwblogon.exe" %AS400% /u %iSeries_User% /p "%password%"

start /B "" "%client_Access_Home%\Emulator\pcsws.exe" %ScriptPath%\ /Q /H
start /B "" "%client_Access_Home%\Emulator\pcsws.exe" %ScriptPath%\ /Q /H


Create a new entry in the task scheduler to be run at server boot.
Select the user it should be run under and tick “Run whether user is logged on or not” and set the bat file defined above under Actions.

The “pause” command is mandatory. If removed, the task will end, the cmd process shuts leaving the pcsws.exe processes up but orphans. The printer writer will remain in the END state on IBM i !
If anybody has a clue as to why, please leave a comment.
cwblogon.exe is far from ideal on the security side, it is best to define a restricted profile! Set the same user in iSeries Navigator or in the session parameters.

This was tested on Windows Server 2012. I have no clue if it works on other OS but there’s no reason why it would not.
You can now schedule reboots anytime you like without having to deal with starting sessions manually.

For printer sessions though, you’re better off printing to a Windows printer share. It’s probably a better and cleaner way to do it.
You can connect with SSH protocol if you want to run shell scripts or CL programs (with the “system” command) and do many other things.

2 responses so far

2 Responses to “Run AS400 Session on Windows Startup”

  1. Alexon 05 Oct 2017 at 4:04 pm

    Can I call a CL Program using this method and logoff immediately afterwards?

  2. daveon 20 Apr 2021 at 8:44 am

    Hi Alex,

    Not sure with this method, let me know if you find out, but it’s probably not the best way.
    2 ways that I can think of:
    – SSH with a private key, you can run CL commands with the system command
    – IBM now provides Ansible that can launch CL commands if you know Ansible

Trackback URI | Comments RSS

Leave a Reply