The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,161 other followers

Impersonation on the iSeries: Changing Profile User

Posted by jpluimers on 2011/10/12

When running on Windows, changing the current user is called impersionation.

There are various ways to do this in Windows, including

On the iSeries, there is only one way, as everything goes through the same API: use QSYGETPH (Get Profile Handle) to verify a username/password combination and obtain a handle to the authentication token, then use QWTSETP (Set Profile Handle) to change the user currently signed on, as for instance mentioned by Colin Williams directing to the CHGCURUSR tool on and an article on Swapping AS/400 User Profiles by Shannon O’Donnel that comes with source code.

On the iSeries, when you are done, you should use QSYRLSPH (Release Profile Handle) when done impersonating, and you need to get the handle from the original user profile if you want to return to it.

The IBM documentation contains a small sample with QSYGETPH, QWTSETP and QSYSRLSPH that sets and restores the profile handle (edit 20120214: it got moved to

Note that on both Windows ans iSeries, impersonation within a process/thread will make it run in the new context, but the process still keeps the identity of the user that started the process.

If you want to change that, then on both you need to start a new process from the impersonated thread.

In Windows, you can combine the impersionation and the creation of a new process by using the CreateProcessWithLogonW function (as mentioned at the Old New Thing by Raymond Chan). I’ve yet to find an equivalent on the iSeries.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: