如何使用“网络服务”帐户启动控制台应用程序

时间:2021-11-12 02:38:05

I have a console application that i would like to run as 'NT AUTHORITY\NetworkService', but i cant remember how to do so - the only reason is that i will be hosting my service in a windows service, but for kerberos authentication testing i want to use the spn that is already at the domain (it does have delegation enabled)

我有一个控制台应用程序,我想运行'NT AUTHORITY \ NetworkService',但我不记得如何这样做 - 唯一的原因是我将在Windows服务中托管我的服务,但对于kerberos身份验证测试我想要使用已经在域中的spn(它确实已启用委派)

In short i can simply convert it from a console app to a windows service, but i was hoping to keep from that.

简而言之,我可以简单地将它从控制台应用程序转换为Windows服务,但我希望保持这一点。

Does anyone know how to do this?

有谁知道如何做到这一点?

1 个解决方案

#1


1  

I don't know how accurate it is, but it is suggested that this might not be possible - see here.

我不知道它有多准确,但有人认为这可能是不可能的 - 见这里。

It might be simplest to port it into a service... for debugging purposes, it is fairly easy to write code that can work either as a service or as a console exe (making it easy to debug, albeit in the wrong identity). I do this all the time...

将它移植到服务中可能是最简单的...出于调试目的,编写可以作为服务或作为控制台exe工作的代码相当容易(使其易于调试,尽管标识错误)。我一直这样做......

Here's an example of this; search in the code for the switches:

这是一个例子;在代码中搜索交换机:

case "-c": 
case "-console":

i.e. with "-c", it runs the code directly, rather than starting the service infrastructure. The code also shows how to have the exe act as a self-installer, which can be very handy.

即使用“-c”,它直接运行代码,而不是启动服务基础结构。该代码还显示了如何使exe作为自安装程序,这可以非常方便。

#1


1  

I don't know how accurate it is, but it is suggested that this might not be possible - see here.

我不知道它有多准确,但有人认为这可能是不可能的 - 见这里。

It might be simplest to port it into a service... for debugging purposes, it is fairly easy to write code that can work either as a service or as a console exe (making it easy to debug, albeit in the wrong identity). I do this all the time...

将它移植到服务中可能是最简单的...出于调试目的,编写可以作为服务或作为控制台exe工作的代码相当容易(使其易于调试,尽管标识错误)。我一直这样做......

Here's an example of this; search in the code for the switches:

这是一个例子;在代码中搜索交换机:

case "-c": 
case "-console":

i.e. with "-c", it runs the code directly, rather than starting the service infrastructure. The code also shows how to have the exe act as a self-installer, which can be very handy.

即使用“-c”,它直接运行代码,而不是启动服务基础结构。该代码还显示了如何使exe作为自安装程序,这可以非常方便。