Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Powershell Script as Windows Service

411 views
Skip to first unread message

tobia...@gmail.com

unread,
Feb 8, 2007, 10:50:35 AM2/8/07
to
Hello everybody,

i am wondering if it is possible to run powershell scripts as windows
service?
embedding my *.ps1 script in a batch file and using instsrv/srvany
allows me to start up my *.ps1 script but when i stop the service, it
seems to stop the running *.bat but not the contained *.ps1
Application...

Any hints?

RichS

unread,
Feb 8, 2007, 12:00:01 PM2/8/07
to
because you are starting the batch file with srvany it is the bat file thats
treated as the service. I think that when the bat file starts PowerShell it
spawns another process outside the service. the service doesn't know
anything about it so leaves powershell running.

you would need to start powershell as the service and put in the script you
want to run as a parameter
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

Brandon Shell

unread,
Feb 8, 2007, 12:04:15 PM2/8/07
to
How did you launch the powershell session via the batch file?

--
Brandon Shell
---------------
Stop by my blog some time :)
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------

<tobia...@gmail.com> wrote in message
news:1170949835.5...@q2g2000cwa.googlegroups.com...

Brandon Shell

unread,
Feb 8, 2007, 12:08:35 PM2/8/07
to
That would only be the case if he used:
start C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command
script.ps1

If he has this in the batch it should block and powershell should terminate
when cmd.exe is killed.
powershell -command script.ps1

Maybe he can post the script

--
Brandon Shell
---------------
Stop by my blog some time :)
http://www.bsonposh.com/
Try the "Search of Powershell Blogs"
--------------------------------------

"RichS" <Ri...@discussions.microsoft.com> wrote in message
news:DABF7B12-F851-4514...@microsoft.com...

tobia...@gmail.com

unread,
Feb 8, 2007, 12:27:37 PM2/8/07
to
On 8 Feb., 18:04, "Brandon Shell" <tshell.m...@gmail.com> wrote:
> How did you launch the powershell session via the batch file?
>
> --
> Brandon Shell
> ---------------
> Stop by my blog some time :)http://www.bsonposh.com/

> Try the "Search of Powershell Blogs"
> --------------------------------------
>
> <tobias.k...@gmail.com> wrote in message

>
> news:1170949835.5...@q2g2000cwa.googlegroups.com...
>
> > Hello everybody,
>
> > i am wondering if it is possible to run powershell scripts as windows
> > service?
> > embedding my *.ps1 script in a batch file and using instsrv/srvany
> > allows me to start up my *.ps1 script but when i stop the service, it
> > seems to stop the running *.bat but not the contained *.ps1
> > Application...
>
> > Any hints?

Hi all,

i started my test.ps1 in a run.bat like
Powershell C:\test.ps1
With this run.bat i "created" a Windows Service with instsrv and
srvany... the usual way.

I solved the problem of "stopping" the service including the
powershell script by using

"powershell C:\test.ps1"

in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aaaa
\Parameters "Application" Key

--> now when i stop the Service (here: aaaa) , also the powershell
script seems to be stopped.

So the solution is not to use the "integration" of a powershell script
in a batch file when it should be run as a windows service.
Just create your Service with "instsrv" and "srvany" the usual way and
use "powershell myscript.ps1" in the registry...

Brandon Shell

unread,
Feb 8, 2007, 1:00:02 PM2/8/07
to
Very Nice... still curious that it didn't work as expected.

--
Brandon Shell
---------------
Stop by my blog some time :)

Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject
--------------------------------------

<tobia...@gmail.com> wrote in message
news:1170955656.9...@q2g2000cwa.googlegroups.com...

0 new messages