Advertisement
Dennisaa

Delete a Service

Mar 7th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $serviceName = "SpeechService"
  2. if (Get-Service $serviceName -ErrorAction SilentlyContinue) {
  3.     #$serviceToRemove = Get-WmiObject -Class Win32_Service -Filter "name='$serviceName'"
  4.     #$serviceToRemove.delete()
  5.     sc.exe delete $serviceName
  6. }
  7. # or you could just do...
  8.  
  9. $secpasswd = ConvertTo-SecureString "EnterYourActualPasswordHere...andThenRemoveallEvidence" -AsPlainText -Force
  10. $mycreds = New-Object System.Management.Automation.PSCredential ("x@y.com", $secpasswd)
  11. $exePath = "c:\scratch\DummyService.exe"
  12. #New-Service -name $serviceName -binaryPathName $binaryPath -displayName $serviceName -startupType Automatic -credential $mycreds
  13. #New-Service -name $serviceName -binaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs" -displayName $serviceName -startupType Automatic -credential $mycreds
  14. #new-service -name TestService -binaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs" -dependson NetLogon -displayName "Test Service" -StartupType Manual -Description "This is a test service."
  15. new-service -name $serviceName -binaryPathName "C:\SayALine.exe" -displayName "Speech Service" -StartupType Manual -Description "This is a speech service."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement