Starting processes under specific credentials from a Windows service

前端 未结 2 2032
轮回少年
轮回少年 2021-01-26 12:46

I\'ve spent a few days on this problem and even though there are tons of different examples online it\'s a tricky problem and I can\'t get them to work in my scenario.

I

2条回答
  •  梦谈多话
    2021-01-26 12:56

    I managed to make the processes start with this code:

    ProcessHelper: http://pastie.org/private/dlkytj8rbigs8ixwtg

    TokenImpersonationContext: http://pastie.org/private/nu3pvpghoea6pwwlvjuq

    The service calls the StartAsUserFromService method, and the process calls the StartAsUserFromApplication method to start its successor.

    I'm using LogonType.Batch in the LogonUser call because the process needs to talk to another WCF service and needs to authenticate. LogonType.Network and LogonType.NetworkClearText could be used, but caused permission issues in the Net.Tcp Port Sharing Service with the Worker user account.

    This answer was helpful: Using Process.Start() to start a process as a different user from within a Windows Service

提交回复
热议问题