Пример #1
0
        public bool Execute(string file, string param, string dir)
        {
            IntPtr sessionTokenHandle = IntPtr.Zero;

            try
            {
                sessionTokenHandle = SessionFinder.GetLocalInteractiveSession();
                if (sessionTokenHandle != IntPtr.Zero)
                {
                    ProcessLauncher.StartProcessAsUser(file, param, dir, sessionTokenHandle);
                }
            }
            catch (System.ComponentModel.Win32Exception ex)
            {
                if (ex.NativeErrorCode == 1008)      //ERROR_NO_TOKEN: No user is logged-on
                {
                    return(false);
                }
                throw ex;
            }
            catch (Exception ex)
            {
                //What are we gonna do?
                throw ex;
            }
            finally
            {
                if (sessionTokenHandle != IntPtr.Zero)
                {
                    NativeMethods.CloseHandle(sessionTokenHandle);
                }
            }
            return(true);
        }