Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Powershell Script as Windows Service

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 02-08-2007   #1 (permalink)
tobias.kuhn@gmail.com
Guest


 

Powershell Script as Windows Service

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?


My System SpecsSystem Spec
Old 02-08-2007   #2 (permalink)
RichS
Guest


 

RE: Powershell Script as Windows Service

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


"tobias.kuhn@gmail.com" wrote:

> 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?
>
>

My System SpecsSystem Spec
Old 02-08-2007   #3 (permalink)
Brandon Shell
Guest


 

Re: Powershell Script as Windows Service

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.kuhn@gmail.com> wrote in message
news:1170949835.557854.291350@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?
>


My System SpecsSystem Spec
Old 02-08-2007   #4 (permalink)
Brandon Shell
Guest


 

Re: Powershell Script as Windows Service

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" <RichS@discussions.microsoft.com> wrote in message
newsABF7B12-F851-4514-96D5-B3B555D166AF@microsoft.com...
> 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
>
>
> "tobias.kuhn@gmail.com" wrote:
>
>> 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?
>>
>>


My System SpecsSystem Spec
Old 02-08-2007   #5 (permalink)
tobias.kuhn@gmail.com
Guest


 

Re: Powershell Script as Windows Service

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.557854.291350@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...



My System SpecsSystem Spec
Old 02-08-2007   #6 (permalink)
Brandon Shell
Guest


 

Re: Powershell Script as Windows Service

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
--------------------------------------

<tobias.kuhn@gmail.com> wrote in message
news:1170955656.944022.247230@q2g2000cwa.googlegroups.com...
> 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.557854.291350@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...
>
>
>


My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a Windows Service run a visual basic script? David .NET General 2 03-26-2008 07:04 AM
What is the MIME type of Windows Powershell script files (.ps1 fil zkyboy PowerShell 3 03-11-2008 07:37 AM
when run powershell script as windows service ,powershell fail powershell fail on winodws 2008 PowerShell 6 01-15-2008 03:20 PM
Powershell or Windows Script Marc Sommer PowerShell 3 12-05-2007 03:20 PM
Script Host Client launched from Windows Service DavidRF Vista security 4 06-27-2007 04:01 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51