Abstractions.WindowsApi.pInvokes.StartUserProcessInSession C# (CSharp) Method

StartUserProcessInSession() public static method

public static StartUserProcessInSession ( int sessionId, string cmdLine ) : bool
sessionId int
cmdLine string
return bool
        public static bool StartUserProcessInSession(int sessionId, string cmdLine)
        {
            IntPtr userToken = IntPtr.Zero;

            try
            {
                // Get user's token from session id, WTSQueryUserToken already returns a primary token for us
                //  so all we then have to do is use it to start the process.
                if (!SafeNativeMethods.WTSQueryUserToken(sessionId, out userToken))
                {
                    LibraryLogging.Error("StartUserProcessInSession({1}, {2}) WTSQueryUserToken Error:{0}", LastError(), sessionId, cmdLine);
                }

                using (Process p = StartProcessWithToken(userToken, cmdLine))
                {
                    bool tmp = p.HasExited; // trow exception if error
                }
            }
            catch
            {
                return false;
            }
            finally
            {
                SafeNativeMethods.CloseHandle(userToken);
            }

            return true;
        }