你能用 Powershell 编写 Windows 服务吗? [英] Can you write Windows services in Powershell

查看:52
本文介绍了你能用 Powershell 编写 Windows 服务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PowerShell 中编写了一个程序,用于循环和检查内容.我想将其转换为 Windows 服务.我已经创建了一个 Windows 服务(在 Admin->Services 中),但我无法启动它.我很确定我缺少系统为了启动/停止/暂停/等服务而需要调用的正确接口.

I have written a program in PowerShell that loops and checks stuff. I would like to convert this into a Windows service. I've created a Windows service (in Admin->Services) but I can't start it. I'm pretty sure I'm missing the proper interface that the system needs to call into in order to start/stop/pause/etc the service.

我可以找到很多在 VB/C#/MS-lang 中执行此操作的示例,但没有关于如何使用 PowerShell 执行此操作的示例.是否有任何文档(或者最好是代码示例)来帮助解决这个问题?

I can find plenty of examples when it comes to doing it in VB/C#/MS-lang but nothing about how to do it using PowerShell. Is there any documentation (or preferably code examples) out there to help with this?

推荐答案

如果您绝对想将 PowerShell 代码执行到服务中,我认为您可以为 PowerShell 代码编写一个 C# 服务包装器.

If you absolutly want to execute your PowerShell code into a service, I think you can write a C# service wrapper for PowerShell code.

您找到了如何使用 C# 创建服务的示例,以及 从 C# 调用 Powershell 很简单.所以我很惊讶,因为小的面向 SrvAny 的 PowerShell 还不存在.

You found examples of how to create a service with C#, and it's simple to call Powershell from C#. So I'am surprised that as small SrvAny oriented PowerShell does not exists yet.

我的建议是,你最好用 C# 作为服务重写你的代码.

My advice here, you better rewrite your code in C# as a service.

这篇关于你能用 Powershell 编写 Windows 服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆