1

I have service running in self hosting application. When request comes, I want to start a process as a user, from which the request had come from. In the example below, first message box shows User1 name, second User2, but the notepad runs as User1. how can I force it to start as User2?

MessageBox.Show(WindowsIdentity.GetCurrent().Name);
using (((WindowsIdentity)RequestContext.Principal.Identity).Impersonate())
            {
                MessageBox.Show(WindowsIdentity.GetCurrent().Name);
                Process.Start("Notepad.exe");
            }
Dmytro Kosh
  • 53
  • 1
  • 7
  • Impersonation is ignored when starting a new process. Perhaps the code at the start of [this question](http://stackoverflow.com/q/38274533/886887) would help? – Harry Johnston Jul 09 '16 at 03:52
  • yes, I plan to try to use [this method](https://msdn.microsoft.com/en-us/library/windows/desktop/ms682429(v=vs.85).aspx) to overcome my problem, but I wonder whether there is better way to do that, without Win API – Dmytro Kosh Jul 10 '16 at 18:23
  • ProcessStartInfo requires username and password. I don't have them, all I have is token – Dmytro Kosh Jul 11 '16 at 11:04
  • OK, I understand now. Someone else may know for sure whether there's a way to do this in .NET without P/Invoking the Win32 API. – Harry Johnston Jul 11 '16 at 21:36
  • I don't think you can do it without P/Invoke, but the good news is that this answer suggest a complete code reference: http://stackoverflow.com/a/38490877/397604 – Itaypk Feb 21 '17 at 07:12

0 Answers0