I'm trying to use a .bat script to stop two services on Windows Server 2008 (using net stop)
I get an error saying:
The service is not responding to the control function.
More help is available by typing NET HELPMSG 2186.
Press any key to continue . . .
Terminate batch job (Y/N)?
Is there any idea what is causing this and how to overcome this problem?
You don't have a batch problem, you have a problem with the service.
NET STOP is trying to stop the service, but the service is not responding to the request.
Related
I have an ASP.NET Core application running a large number of RESTful calls on a server and I need to add in the ability to ping the local devices to ensure they are alive. That "ping" is actually a RESTful call in and of itself with a boolean response.
While I could simply write a Windows Service to do this work, I am hoping that there is some way to run this process continuously within the context of my application. I tried running async Tasks every way I could think of but I am clearly doing something wrong.
I found AsyncContext (https://github.com/StephenCleary/AsyncEx/wiki/AsyncContext) and have used it to run other things but I am clearly not using it correctly as the loop hangs the entire application.
Does anybody have a suggestion?
Thank you!
From our Advanced Installer setup, we install/upgrade a service that needs up to a minute to shut down. We cannot decrease the time it needs, and it will be shut down after a minute.
If AI tries to stop that service, it comes up with an error message after less than a minute ("The setup was unable to automatically close all requested applications. Please ensure that the applications holding files in use are closed before continuing with the installation").
I have not found an option in Advanced Installer Professional to change the timeout of the wait.
Is this possible?
I don't think this is possible. You can try to use a custom action to stop the service. That means you could write your own code to trigger a service stop operation and wait for a minute. This code can be executed as a custom action.
To make sure the described error message is not thrown you should execute your custom action before "Paths Resolution" action.
Our application is DDE enabled. It acts as a server. It has its own file type, and offers an 'Open' command.
When launching application from a right-click on a saved file (ie reading HKEY_CLASSES_ROOT-----\shell etc) we sometimes get "there was a problem sending the command to the program". Especially win10.
On problem PCs we test a VBA script that triggers our exe, waits a second, and then sends DDE commands. This works well.
We conclude we need a pause, or to increase timeout on the DDE conversation.
Can this be done?
Is there a globally effective registry setting?
Any ideas?
No, you cannot pause or increase the DDE timeout.
Instead, you should look at possible problems with your application.
It is likely that your program is starting to pump messages before your DDE server is up and running. As soon as you start handling messages, Windows assumes your DDE server is running. So, it sends you the message, but your server is not up to receive it yet. Make sure that no thread in the program is handling Windows messages before the DDE server is setup.
I run my programs and want them to go on running although i logged off from the system.
Is there a way to do this without windows services?
Here is what i want:
I remote connect to the server,
I log in to the server,
I start my program.
I log off from the server but my program continues to running...
thanks.
The only solution that I can think of is running your program as a Windows Service .
there is nothing wrong with using a service. You could go to the length of creating a 'server' part of the program that runs as a service and a 'client' gui. But I assume you aren't talking about software you developed, but something else.
The other way would be to use Scheduled Tasks, that would run a program even if user isn't logged in, useful for backup scripts etc.
An alternative would be to write your program, and schedule it to run in the scheduler.
It depends if you want it to run constantly, or not.
I guess you could follow these instructions to configure your program to run as a service. You will set it's "startup type" to manual so that it will not start each time the operating system starts but instead you log in and start the service manually. Then, when you log off, the service continues running.
I'm writing a simple Windows Service that sends out emails to all employees every month. My question is, how to stop itself when it's done? I'm a noobie in this field so please help me out. Really appreciated.
It will be deployed on the server to be run monthly. I did not start this thing and the code was given to me like that. It is written in VB.NET and I'm asked now to change a few things around it. I noticed that there is only 'Sub OnStart' and wondered when the service would stop? After the main sub is done, what it the status of this service? Is it stopped or just hung in there? Sorry, as I said, I am really new to this....
If you have a task that recurs monthly you may be better off writing a console app, and then using Windows Task Scheduler to set it to run monthly. A service should be used for processes that need to run for a long time or constantly, with or without a user logged on
As every other answer has noted, it sounds like this should be an executable or script that you run as a scheduled task.
However, if you are obligated for some reason to run as a Windows Service and you're working in .NET, you just have to call the Stop() method inherited from ServiceBase once your service completes its work. From the MSDN documentation for the method:
The Stop method sets the service state
to indicate a stop is pending and
calls the OnStop method. After the
application is stopped, the service
state is set to stopped. If the
application is a hosted service, the
application domain is unloaded.
There's one important caveat here: the user account under which the service is running must have permission to stop services (which is a topic for ServerFault).
Once a service's OnStart method completes, it will continue running (doing nothing) until something tells it to stop in one of the following ways:
Programatically, by calling Stop
within the service itself or from an
external process using the method
Colin Gravill describes in his
answer.
Via the command-line.
Through the windows Computer Management console's "Services" panel.
If this is a Win32 service (i.e. written in C or C++), then you simply call SetServiceStatus(SERVICE_STOPPED) and return from ServiceMain.
On the other hand, if you're just sending emails once a month, why are you using a service at all? Use the Windows Task Scheduler and run a normal application or script.
net stop [service_name] ...on the command line will do it too.
But, I agree with everyone else; it seems that Windows Task Scheduler will meet your needs better.
It might be better to write this as a scheduled task, it would certainly be easier to develop initially. Then it would naturally terminate and wouldn't be consuming resources for the rest of the month.
To answer the original question, you can get a list of the current running services in C#
services = System.ServiceProcess.ServiceController.GetServices();
Then look for the one you want and set the status to stopped
locatedService.Status == ServiceControllerStatus.Stopped
Full example on msdn
Is there a reason it has to be a Windows service? If not, then follow #Macros solution. However, if it does, then why stop the service? If you stop it, then it'll just have to be restarted when the emails need to be sent. Based on your description, it doesn't sound like it would require a lot of resources, so I'd suggest just installing it and letting it run, firing up once a month to send the emails.
here's what i did in a similar situation.
windows service runs 24/7 and processes work units. it gets work units through a database view.
table Message
ProcessingStartTime
CompletionDTE
...
the database view only pulls records marked not-complete and have a ProcessingStartTime in the past. So after the service confirms the transaction it executes a stored procedure that updates the database record. For this system, end-user upload excel files to asp.net webfrom that imports them into the database.