有没有一种简单的方法来制作 Windows 服务?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7073557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:51:57  来源:igfitidea点击:

is there an easy way to make a windows service?

windowswindows-services

提问by Narcolapser

Question: Is there a way to make a program run with out logging in that doesn't involve the long painful task of creating a windows service, or is there an easy way to make a simple service?

问题:有没有一种方法可以让程序在不登录的情况下运行,而不涉及创建 Windows 服务的长期痛苦任务,或者有没有一种简单的方法来创建一个简单的服务?



Info: I'm working on a little project for college which is a simple distributed processing program. I'm going to harness the computers on campus that are currently sitting completely idle and make my own little super computer. but to do this I need the client running on my target machines.

信息:我正在为大学做一个小项目,这是一个简单的分布式处理程序。我将利用校园里目前完全闲置的计算机来制作我自己的小型超级计算机。但要做到这一点,我需要在我的目标机器上运行客户端。

Through a little mucking around on the internet I find that what I need is a service, I also find that this isn't something quite as simple as making a scheduled task or dropping a .bat file into the start up folder.

通过在 Internet 上的一些探索,我发现我需要的是一项服务,我还发现这不像制定计划任务或将 .bat 文件放入启动文件夹那么简单。

I don't need a lot. if I could just get it to call "python cClient.py" i'm completely set. Is there an easy way to do this? like adding a key in the registry some where? or do I have to go through the whole song and dance ritual that microsoft has made for setting up a service?

我不需要很多。如果我可以让它调用“python cClient.py”,我就完全设置好了。是否有捷径可寻?喜欢在注册表中添加一个键在哪里?或者我是否必须经历微软为设置服务所做的整个歌舞仪式?

回答by Wandering Penguin

If you already have the executable you wish to run as a service you can use "sc" built into the OS already. Microsoft details the procedure here: http://support.microsoft.com/kb/251192

如果您已经拥有希望作为服务运行的可执行文件,您可以使用操作系统内置的“sc”。Microsoft 在此处详细介绍了该过程:http: //support.microsoft.com/kb/251192

example: sc create "My Service" c:\temp\executable.exe

C:\Users\somebody>sc create

C:\Users\somebody>sc 创建

DESCRIPTION:      Creates a service entry in the registry and Service Database. USAGE: sc <server> create [service name] [binPath= ] <option1> <option2>...

OPTIONS: NOTE: The option name includes the equal sign.
      A space is required between the equal sign and the value.   type= <own|share|interact|kernel|filesys|rec>
       (default = own)   start= <boot|system|auto|demand|disabled|delayed-auto>
       (default = demand)   error= <normal|severe|critical|ignore>
       (default = normal)   binPath= <BinaryPathName>   group= <LoadOrderGroup>   tag= <yes|no>   depend= <Dependencies(separated by / (forward slash))>   obj= <AccountName|ObjectName>        (default = LocalSystem)   DisplayName= <display name>   password= <password>

回答by Jacob Seleznev

The Windows NT Resource Kit introduced the Srvany.exe command-line utility, which can be used to start any Windows NT/2000/2003 application as a service.

Windows NT Resource Kit 引入了Srvany.exe 命令行实用程序,该实用程序可用于将任何 Windows NT/2000/2003 应用程序作为服务启动。

You can download Srvany.exe here.

您可以在此处下载 Srvany.exe 。

回答by John Saunders

Use Visual Studio and just create yourself a Windows Service project. I think you'll find it very easy.

使用 Visual Studio 并为自己创建一个 Windows 服务项目。我想你会发现这很容易。

回答by Jacob Seleznev

Can you schedule a task? More info here.

你能安排一个任务吗?更多信息在这里

回答by Simon M?Kenzie

You can create a startup script and globally apply it to your machines via group policy - just add it via gpedit.msc:

您可以创建一个启动脚本并通过组策略将其全局应用到您的机器 - 只需通过 gpedit.msc 添加它:

Add startup script via group policy

通过组策略添加启动脚本