The problem with Shrike’s answer is that it does not work with a user connected over RDP.
Here is my solution, which properly determines the current user’s session before creating the process. It has been tested to work on XP and 7.
https://github.com/murrayju/CreateProcessAsUser
Everything you need is wrapped up into a single .NET class with a static method:
public static bool StartProcessAsCurrentUser(string appPath, string cmdLine, string workDir, bool visible)