Stopping Avecto Defendpoint programmatically - powershell

Before anyone says anything about access rights...
I have full access to services and can manually stop both the Avecto Defendpoint Service and the Avecto Defendpoint ePO Interface. And, all users who will be using this application will also have admin rights.
Im trying to find a way to stop the Avecto Defendpoint service through PowerShell. I've tried...
Right-click on PowerShell (Run as admin)
Stop-Service -Name "Avecto Defendpoint Service"
With this as a response...
Stop-Service : Service 'Avecto Defendpoint Service (Avecto Defendpoint
Service)' cannot be stopped due to the following error: Cannot open Avecto
Defendpoint Service service on computer '.'.
I've also tried using the -Force parameter with the same result. If I manually disable Avecto prior to running the PowerShell I can manually start the service back up again and THEN I can kill it as intended from the PowerShell; but this defeats the purpose of embedding the functionality into the program.
Any thoughts or suggestions?

You can use the following to stop Defendpoint from working:
Stop-Service -InputObject "Avecto Defendpoint Service" -Force
Once you are finished and need to re-enable it, use this:
Start-Service -InputObject "Avecto Defendpoint Service"

Related

Stop a service so it can be uninstalled

I am doing some automated uninstalls of Autodesk software, and Autodesk has once again screwed the pooch with their uninstalls. Their uninstall is supposed to do reference counting on certain shared components, like their Single Signor Service, Autodesk Genuine Service, Licensing service, etc. The problem is, when you are uninstalling that last ADSK product, the uninstaller is too stupid to stop the service, so their uninstaller fails with a 1603 fatal error. Last year you could stop the services before you started the uninstall, but this year I am getting this error
Stop-Service : Service 'Autodesk Access Service Host (Autodesk Access Service Host)' cannot be stopped due to the following error: Cannot open Autodesk Access Service Host service on computer '.'.
When using this code
Get-Service -Name "Autodesk Access Service Host" | Stop-Service -Force -NoWait
I have verified with
(Get-Service -Name "Autodesk Access Service Host").CanStop
that service can be stopped. At least according to the property.
I also tried
Start-Process "$env:WINDIR\system32\sc.exe" \\.,stop,"Autodesk Access Service Host" -NoNewWindow -Wait
while ((Get-Service -ComputerName '.' -Name "Autodesk Access Service Host" |
Select -ExpandProperty Status) -ne 'Stopped') {
Write-Host "Waiting for service to stop..."
Start-Sleep -Seconds 10
}
And that has run for 15 minutes with no results. Interestingly I CAN disable the service, but I really don't want that. I just want to stop it temporarily, so IF the Autodesk uninstall that is running is the last one with a dependency on this service will uninstall it correctly and returns the correct exit code of 0.
EDIT: I tried
sc stop "Autodesk Access Service Host"
from an elevated command prompt and that shows
STATE : 3 STOP_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
so not really sure how to take STOP_PENDING along with NOT_STOPPABLE, nor why this would say NOT_STOPPABLE when the property above shows true.

Why would Get-Service not find the service with powershell

I am having problems with a powershell script.
I wrote a script that would search for a windows service with a specific name, and it would Stop or Start this service.
It works when I run it on a server which I log into with a service account that I know that can access the service console. However when it runs off of my build server, the script is no longer able to find the services. I tried giving the service account that runs script the same privaledges as the other service account but that doesn't seem to work.
[System.ServiceProcess.ServiceController]$service = Get-Service -Name $ServiceName -ComputerName $Remoteserver -ErrorAction SilentlyContinue
That is the line that is not longer able to find the service. What am I doing wrong. Is there a way to impersonate a user that can find the service? Any help would be appreciated.
You could try supplying the credentials of the service account using the -Credential parameter. However, since you imply that it used to work with the account that runs the script remotely and no longer does, I think a more likely culprit is that $ServiceName used to only match one service on the target computer, and now there is another service whose name matches that string. If more than one service matches the -Name parameter, Get-Service returns an array of ServiceController objects.
Try running it without ErrorAction -SilentlyContinue. If you get the following error message, then that's what's happening:
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.ServiceProcess.ServiceController".
If you get a different error message, please add the full error message to the question.

Getting error when trying to start windows service through Powershell

So I am trying to use Powershell to start a windows service. I have the service installed just fine, but when I call Start-Service -Name $name I am recieving the following error.
Start-Service : Service 'IncidentManagementService (IncidentManagementService)' cannot be started due to the following error: Cannot start service IncidentManagementService on computer '.'.
I have powershell running as an Administrator and I also tried going under the properties of the .exe file and checking "run as admin" to no avail.
If anyone could give me a clear reason as to why the service is not starting it would be much appreciated.
In my case the service is disabled... so is the reason I am getting that error.

Disable Popups when Stoping/Starting Services in Batch File

I have a DOS batch file that Stops and Starts Windows services. We ran into a situation where this activity failed. When on the server, I launched the server's Service application. I attempted to stop the service and got a popup message. I am theorizing that the popup interactivity is why the stop of the service failed. Is there a way, using the SC command, to disable the popup functionality? Below is the code to stop the service.
sc \\%SERVER% stop %SERVICE_NAME%
Are you set on using sc to stop the service? Perhaps an alternate command would not be stopped by the error dialog. I would suggest trying net stop "Service Name", however that would not allow you to stop the service remotely (without 3rd party tools).
If PowerShell is an option, try this (combining ideas from this SO thread with this one):
Start-Service -inputobject $(get-service -ComputerName %SERVER% -Name %SERVICE_NAME%) -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
Also, you could try using wmic to stop the service like this:
wmic /node:"%SERVER%" service where name="%SERVICE_NAME%" call stopservice

PowerShell Stop-Service/Start-Service not working on a specific server

I have three servers, let's call them Deploy1, Deploy2, Target.
All servers are running Windows Server 2008R2, fully updated.
A domain user, admin1, is configured as administrator on all servers, and this is the user I'm running all the commands with.
The following command works on Deploy1:
Get-Service "MyService" -ComputerName Target | Stop-Service
When running the same command on Deploy2, the command fails with the following message:
Cannot find any service with service name 'MyService'.
On Deploy2, the following command works, and displays the service and its status.
Get-Service "MyService" -ComputerName Target
Now, I know there are other ways to stop/start services via PowerShell, but I like this one as it automatically waits for the server to actually stop/start.
So what could be wrong with Deploy2?
Powershell v2.0 has a bug (feature?) in how the object returned by Get-Service is implemented. It does not actually set the ComputerName property correctly. Because of this, it can only affect local services. If you upgrade to Windows Management Framework 3.0 (and consequently Powershell v3) the bug is fixed and will work correctly.
Does this work? If not, is there an error produced?
(Get-Service "MyService" -ComputerName Target).Stop()