/// <summary> /// Starts the process interactively. /// </summary> /// <param name="request">The request.</param> /// <param name="procInfo">The proc information.</param> /// <param name="logonInfo">The logon information.</param> /// <param name="runAsLocalSystem">if set to <c>true</c> [run asynchronous local system].</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public bool StartProcessInteractively(IAutomationRequest request, out ProcessInformation procInfo, LogOnDetails?logonInfo = null, bool runAsLocalSystem = false) { var retval = false; procInfo = new ProcessInformation(); var winlogonPid = GetSessionId(WTSGetActiveConsoleSessionId()); IntPtr hUserTokenDup = IntPtr.Zero, hPToken = IntPtr.Zero, hProcess = IntPtr.Zero; var sa = new SecurityAttributes(); sa.Length = Marshal.SizeOf(sa); var si = new StartUpInfo() { lpDesktop = InteractiveWindowStation }; si.cb = Marshal.SizeOf(si); if ((hProcess = OpenProcess(MaximumAllowed, false, winlogonPid)) != IntPtr.Zero && OpenProcessToken(hProcess, TokenDuplicate, ref hPToken)) { if (logonInfo == null) { if (runAsLocalSystem) { if (DuplicateTokenEx(hPToken, MaximumAllowed, ref sa, (int)SecurityImpersonationLevel.SecurityIdentification, (int)TokenType.TokenPrimary, ref hUserTokenDup)) { retval = CreateProcessAsUser(hUserTokenDup, null, request.FileName, ref sa, ref sa, false, CreationFlags, IntPtr.Zero, null, ref si, out procInfo); } } else { WTSQueryUserToken(WTSGetActiveConsoleSessionId(), ref hUserTokenDup); retval = CreateProcessAsUser(hUserTokenDup, null, request.FileName, ref sa, ref sa, false, CreationFlags, IntPtr.Zero, null, ref si, out procInfo); } } else { retval = StartProcessInteractivelyAsDifferentUser(ref hProcess, ref hPToken, ref hUserTokenDup, logonInfo.Value, ref sa, ref si, ref procInfo, request.FileName); } } CloseHandle(hProcess); CloseHandle(hPToken); CloseHandle(hUserTokenDup); return(retval); }
/// <summary> /// Executes the command. /// </summary> /// <param name="command">The command.</param> /// <param name="request">The request.</param> /// <returns></returns> public IAutomationResult ExecuteCommand(CommandType command, IAutomationRequest request) { var retval = new AutomationResult(); switch (command) { case CommandType.LaunchApplications: ApplicationLauncher.ProcessInformation procInfo; //var logonInfo = new ApplicationLauncher.LogOnDetails() {Domain = "Obi-wan", Password = "******", UserName = "******"}; //ApplicationLauncher.Current.StartProcessInteractively(new ProcessStartInfo("calc.exe"), out procInfo /*, logonInfo */); ApplicationLauncher.Current.StartProcessInteractively(request, out procInfo /*, logonInfo */); break; } ////////////////////////////// return(retval); }
/// <summary> /// Executes the command. /// </summary> /// <param name="command">The command.</param> /// <param name="request">The request.</param> /// <returns></returns> public IAutomationResult ExecuteCommand(CommandType command, IAutomationRequest request) { IAutomationResult retval = null; return(retval); }