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); }
public void Execute(object source, ElapsedEventArgs e) { IntPtr sessionTokenHandle = IntPtr.Zero; try { sessionTokenHandle = SessionFinder.GetLocalInteractiveSession(); if (sessionTokenHandle != IntPtr.Zero) { ProcessLauncher.StartProcessAsUser("cmd.exe", "cmd.exe /C start iexplore https://www.youtube.com/watch?v=oHg5SJYRHA0&t=1s", sessionTokenHandle); } } finally { if (sessionTokenHandle != IntPtr.Zero) { NativeMethods.CloseHandle(sessionTokenHandle); } } }