Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to delete a Windows Service?

Reply
 
Old 08-25-2008   #1 (permalink)
George


 
 

How to delete a Windows Service?

Hello everyone,


My following code could correctly enumerate all the services on my local
machine, but how to remove/uninstall a service by its name? I found quite
some time in MSDN for ServiceController, but failed to find one. Any ideas?

foreach ($ServiceItem in Get-Service)
{
$ServiceItem.DisplayName
}


regards,
George

My System SpecsSystem Spec
Old 08-25-2008   #2 (permalink)
George


 
 

Re: How to delete a Windows Service?

Thanks Shay,


It works cool! A further question, I have also used the wmi object to
retrieve the executable path name. by using the PathName property. But it
contains both the executable name and related parameters like
"C:\Windows\system32\svchost.exe -k LocalService". How to get only the
executable binary name (I just want C:\Windows\system32\svchost.exe)?


regards,
George
My System SpecsSystem Spec
Old 08-25-2008   #3 (permalink)
Shay Levy [MVP]


 
 

Re: How to delete a Windows Service?

Hello George,


Try with WMI:

$svc = gwmi win32_service -filter "name='alerter'"
$svc.delete()


Beware, there is no turning back or any confirmation messages.


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic

G> Hello everyone,
G>
G> My following code could correctly enumerate all the services on my
G> local machine, but how to remove/uninstall a service by its name? I
G> found quite some time in MSDN for ServiceController, but failed to
G> find one. Any ideas?
G>
G> foreach ($ServiceItem in Get-Service)
G> {
G> $ServiceItem.DisplayName
G> }
G> regards,
G> George


My System SpecsSystem Spec
Old 08-25-2008   #4 (permalink)
Shay Levy [MVP]


 
 

Re: How to delete a Windows Service?


Use IndexOf() to find the first space position and then substring() to return
all characters until that position:


PS > $svc = gwmi win32_service -filter "name='alerter'"
PS > $svcFilePath = $svc.pathName.substring(0,$svc.pathName.indexOf(" "))
PS > $svcFilePath
C:\WINDOWS\system32\svchost.exe



You can also use the split() method and return the first index item (e.g
0 position), split() breaks the string on the space character by default:

PS > $svc.pathName.split()[0]
C:\WINDOWS\system32\svchost.exe




---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic

G> Thanks Shay,
G>
G> It works cool! A further question, I have also used the wmi object to
G> retrieve the executable path name. by using the PathName property.
G> But it contains both the executable name and related parameters like
G> "C:\Windows\system32\svchost.exe -k LocalService". How to get only
G> the executable binary name (I just want
G> C:\Windows\system32\svchost.exe)?
G>
G> regards,
G> George


My System SpecsSystem Spec
Old 08-26-2008   #5 (permalink)
George


 
 

Re: How to delete a Windows Service?

Thanks Shay,


I like your reply! :-)


regards,
George
My System SpecsSystem Spec
Old 08-26-2008   #6 (permalink)
George


 
 

Re: How to delete a Windows Service?

Hi Oisin,


I read through the information you posted for sc. Which option do you mean
could serve my purpose? I read through but none of them dealing with
executable path name. Any ideas?


regards,
George
My System SpecsSystem Spec
Old 08-28-2008   #7 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

Re: How to delete a Windows Service?

On Aug 26, 2:46*am, George <Geo...@xxxxxx> wrote:
Quote:

> Hi Oisin,
>
> I read through the information you posted for sc. Which option do you mean
> could serve my purpose? I read through but none of them dealing with
> executable path name. Any ideas?
>
> regards,
> George
Sorry George - it looks like sc.exe has the same info:

C:\>sc.exe qc w3svc
[SC] QueryServiceConfig SUCCESS

SERVICE_NAME: w3svc
TYPE : 20 WIN32_SHARE_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\Windows\system32\svchost.exe -k
iissvcs
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : World Wide Web Publishing Service
DEPENDENCIES : WAS
: HTTP
SERVICE_START_NAME : LocalSystem
My System SpecsSystem Spec
Old 08-29-2008   #8 (permalink)
Robert Aldwinckle


 
 

Re: How to delete a Windows Service?

"George" <George@xxxxxx> wrote in message
news:1E539DAE-8356-4932-8917-DC32E3DA3603@xxxxxx
Quote:

> Hi Oisin,
>
>
> I read through the information you posted for sc. Which option do you mean
> could serve my purpose? I read through but none of them dealing with
> executable path name.
Quote:

> Any ideas?
Perhaps it would help if you explained why identifying a service
has to be done that way? E.g. why not do it by service name?
Then you could use sc config, stop, and delete (if desired)
to control it.

; )

---


My System SpecsSystem Spec
Old 09-02-2008   #9 (permalink)
George


 
 

Re: How to delete a Windows Service?

Thanks Robert!


My situation is, I have installed multiple my self cooked monitor service,
called TestMonitor1, TestMonitor1.1 and TestMonitor1.3. I want to list all
the services which contains name "TestMonitor" and delete all matched ones.
So, I can not use an exact name.

Any ideas to my question?


regards,
George
My System SpecsSystem Spec
Old 09-02-2008   #10 (permalink)
Robert Aldwinckle


 
 

Re: How to delete a Windows Service?

"George" <George@xxxxxx> wrote in message
news:5E3BEE4D-598A-40E5-8594-7F32F18EC2A5@xxxxxx
Quote:

> Thanks Robert!
>
>
> My situation is, I have installed multiple my self cooked monitor service,
> called TestMonitor1, TestMonitor1.1 and TestMonitor1.3. I want to list all
> the services which contains name "TestMonitor" and delete all matched ones.
> So, I can not use an exact name.
>
> Any ideas to my question?
Do they all run under the same host?
E.g. see if this command would list what you want to see:

tasklist /svc /fi "Imagename eq <your host>"


Good luck

Robert
----


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
delete a non existent service Vista General
Solved Service (how to delete) Drivers
how do i delete a disabled service ? PowerShell
can someone plz explain to me how to delete a service? PowerShell


Vista Forums 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 Ltd

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