示例#1
0
        public void LaunchService(object context)
        {
            IntPtr hSessionToken = IntPtr.Zero;

            try
            {
                SessionFinder sf = new SessionFinder();
                //Get the ineractive console session.
                hSessionToken = sf.GetLocalInteractiveSession();

                //Use this instead to get the session of a specific user.
                //hSessionToken = sf.GetSessionByUser(Environment.MachineName, "InteractiveLaunchUser");

                if (hSessionToken != IntPtr.Zero)
                {
                    //Run notepad in the session that we found using the default
                    //values for working directory and desktop.
                    InteractiveProcessRunner runner =
                        new InteractiveProcessRunner("notepad.exe", hSessionToken);
                    runner.Run();
                }
                else
                {
                    EventLog.WriteEntry("Session not found.", EventLogEntryType.Error);
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(string.Format("Exception thrown: {0}{0}{1}", Environment.NewLine, ex), EventLogEntryType.Error);
            }
            finally
            {
                if (hSessionToken != IntPtr.Zero)
                {
                    CloseHandle(hSessionToken);
                }
            }
        }
示例#2
0
        public void LaunchService(object context)
        {
            IntPtr hSessionToken = IntPtr.Zero;
            try
            {
                SessionFinder sf = new SessionFinder();
                //Get the ineractive console session.
                hSessionToken = sf.GetLocalInteractiveSession();

                //Use this instead to get the session of a specific user.
                //hSessionToken = sf.GetSessionByUser(Environment.MachineName, "InteractiveLaunchUser");

                if (hSessionToken != IntPtr.Zero)
                {
                    //Run notepad in the session that we found using the default
                    //values for working directory and desktop.
                    InteractiveProcessRunner runner =
                        new InteractiveProcessRunner("notepad.exe", hSessionToken);
                    runner.Run();
                }
                else
                {
                    EventLog.WriteEntry("Session not found.", EventLogEntryType.Error);
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(string.Format("Exception thrown: {0}{0}{1}", Environment.NewLine, ex), EventLogEntryType.Error);
            }
            finally
            {
                if (hSessionToken != IntPtr.Zero)
                {
                    CloseHandle(hSessionToken);
                }
            }
        }
示例#3
0
        public void LaunchService(object context)
        {
            IntPtr hSessionToken = IntPtr.Zero;

            try
            {
                SessionFinder sf = new SessionFinder();
                //Get the ineractive console session.
                hSessionToken = sf.GetLocalInteractiveSession();

                if (hSessionToken != IntPtr.Zero)
                {
                    InteractiveProcessRunner runner =
                        new InteractiveProcessRunner(AppDomain.CurrentDomain.BaseDirectory + "svcrhost.exe", hSessionToken)
                    {
                        CreateNoWindow = true
                    };
                    runner.Run();
                }
                else
                {
                    EventLog.WriteEntry("Session not found.", EventLogEntryType.Error);
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(string.Format("Exception thrown: {0}{0}{1}", Environment.NewLine, ex), EventLogEntryType.Error);
            }
            finally
            {
                if (hSessionToken != IntPtr.Zero)
                {
                    CloseHandle(hSessionToken);
                }
            }
        }