Is the Windows Service installed or not? - command-line

Simple explanation:
Installed a Windows Service using sc create. It appeared to work
Tried to run the service using sc start. Message: "The specified service does not exist as an installed service."
Run sc create again. "The Specified Service already exists."
What gives? Have I created a Schrodinger's Service?

Related

Using SC.exe post installUtil

I am trying to understand what is the correct way to uninstall a service.
According to Microsoft here, there are two ways to uninstall a service:
// Using installutil
installutil -u <yourproject>.exe
// Or using Powershell
Remove-Service -Name "YourServiceName"
In both examples, Microsoft states the following thing:
After the executable for a service is deleted, the service might still be present in the registry. If that's the case, use the command sc delete to remove the entry for the service from the registry.
sc.exe delete "YourServiceName"
Assuming most people will run a script to uninstall a given service using one of the above methods, how can we determine (from a batch or powershell script) if the uninstall worked properly or not (so that I can only conditionally run sc.exe)? In other words, how can we check that a service is still in the registry as per the Microsoft quote.
Also, I have been so far using sc.exe without prior uninstalling and it seems to have the desired effect.
ie. My service gets removed from the list of running Windows services and I am able to start with a fresh new installation of my service.
Is this a bad approach? If so, why is it a bad approach?

Service fabric failing with Service Status: fabric:/testsfApplication/tessf is not ready, no container is running

I have a Asp.net Core stateless Service fabric application which was working fine locally but suddenly started giving the above errors on build and deploy. I reset docker locally and also service fabric but it still fails with the same error. I tried to then create a test application which is just an Asp.net core web api with a values controller and converted it into a service fabric application. It also fails with the same error.
I checked my event log and can see this error message from docker
Handler for POST /containers/create returned error: invalid volume specification: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\5rn5xyjl.zea\NanoUtilities:c:\remote_debugger_utilites:ro': invalid mount config for type "bind": bind source path does not exist.
Not sure what is going wrong. Any pointer please ?

Not able to stop the service on UWP appx launch

I have created appx using makeappx tool. After installing appx,on launch I have added below code to stop the service:
ServiceController sc = new ServiceController("MyService");
string servicestatus = sc.Status.ToString();
if (servicestatus == "Running")
{
sc.Stop();
}
On launch I found the service was not stop and getting an exception.But when I run the same appx from start menu with run as administrator I found service was getting stop. I think the issue was related with admin previlages as I know appx always launch with fulltrustprocess and not with adminprevilages.
It will be great help if we can stop the service on appx launch itself.
This is to be expected; if you launch CMD as a normal user and try to stop a service, you will get Access Denied:
C:\Users\Peter>net stop "Bonjour Service"
System error 5 has occurred.
Access is denied.
When running elevated, it works:
C:\Users\Administrator>net stop "Bonjour Service"
The Xamarin Bonjour Service service is stopping.
The Xamarin Bonjour Service service was stopped successfully.
Apps converted via the Desktop Bridge cannot auto-elevate; the user has to do that.

Can not install a poweroff service

Actually I try to install a service called poweroff. This service normally will be installed from a software also called poweroff.
You find it here under old projects:
http://users.telenet.be/jbosman/applications.html
Until now on each pc i want to install the service I use an .cmd file with the content
poweroff.exe shutdown -create_service -msg "This computer will be shut
down!" -warn -warntime 10 -wait 10 -force -allow_remote -remote_port
3210 -remote_pswd password
it creates the service so I can see it inside the services.msc program.
But now on one pc this command do nothing and when I try to create the service inside the poweroff program there comes an message "Access denied".
Because I logged on as administrator I think not that it is an right problem.
Do anyone have an idea why the service will not created?
It seems that the problem was the access to the folder C:\Windows\System32.
After adding the poweroff.exe file to this folder the service could be created without problems.
Thanks to Jorgen Bosman for helping me to find this solution.

WindowsIdentity throwing a "There are currently no logon servers available to service the logon request"

The code below works fine when running from a Console C# application:
System.Security.Principal.WindowsIdentity wi = new System.Security.Principal.WindowsIdentity("User001");
but when I try to add it into a class inside my web application I get:
{There are currently no logon servers available to service the logon request}
at System.Security.Principal.WindowsIdentity.KerbS4ULogon(String upn)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName, String type)
at System.Security.Principal.WindowsIdentity..ctor(String sUserPrincipalName)
...
I am assuming this is related to Kerberos and since Web Applications run under an Application Pool I wonder if I need to register a SPN or do something extra here to get this to work(for the local Account).
The console app runs under my DOMAIN\USER001 and
the Web app (App Pool) runs under MY_LOCAL_MACHINE\USER001
so I am trying to verify if I need to run SetSPN.exe or not and what is the command line.
Thank you
I had the same issue in my 2008R2 VM running SP2010 with a backend WCF service. In the service I was calling
WindowsIdentity id = new WindowsIdentity("MyApplicationUser");
You need to make sure your NetLogon service is running. If you are running a VM, you will need to configure the DNS role in order for this service to start. Once I did this, my code worked.