Hi, I suggest please stick to the same approach how you are doing it manually. If you are not comfortable with using command X, use other options which exist for logging of mainfrmae ( like Logoff command) and once u are logged off, u can close the window by exit option in files or any other way.
Safe log off from application is necessary so that it will end the current user session.
------------------------------
Narayan Shrawagi
Senior Consultant
T systems India private limited
Europe/London
------------------------------
Narayan