Can you write Windows Services in Powershell

I wrote a program in PowerShell that sings and verifies things. I would like to convert this to a windows service. I created a Windows service (in Admin-> Services), but I cannot start it. I am sure that I am missing the correct interface that the system must call to start / stop / pause / etc service.

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

+2
source share
5 answers

If you absolutely want to run your PowerShell code in a service, I think you can write a C # service wrapper for PowerShell code.

You have found examples of how to create a service with C #, and simply call it Powershell with C # . Therefore, I am surprised that since a small SrvAny-oriented PowerShell does not exist yet,

My advice here is to better rewrite your code in C # as a service.

+2
source

There are a few questions here:

  • Are you sure you really need a service? I agree with the comments about using the scheduler to perform periodic tasks. The scheduler can run tasks as an administrator.
  • API , .
  • CreateProcessAsUser, , SCM , script.

( ), , , . PowerShell script . , - srvany, Windows Server 2003 Resource Kit, .

+4
+3

, SrvAny.exe Microsoft ( , , Windows 2000 Resource Kit. (.exe,.cmd ..). VBScripts, - Srvany.exe, Windows 2003 Windows 2008 ( 64-). 100% ( script ), Windows, (.. /Startup, , , . SrvAny.exe( ). Windows, . , , , srvany.exe

+2
source

http://www.firedaemon.com/

Allows you to run something as a service. There are also free alternatives to this application, which does the same.

+1
source

All Articles