Windows service UPS (uninterruptible power supply) service - turn off the UPS?

I am using UPS service to monitor the status of my UPS from an application - the key in HKLM \ SYSTEM \ CCS \ Services \ UPS \ Status has all the information you can get from the power control panel. BUT. I would like to say that the UPS will disconnect from my application as well. I know the service can tell the UPS to shutdown - for example, after starting a set number of minutes on battery - and I'm wondering if there is some command I can send to the service to initiate a shutdown manually.

I am having trouble finding this information - people tend to get the error "Uninterrupted" (hrm, Firefox with red, but they have no alternative) and "UPS" just gets hits for the delivery service. Maybe I can do something via System.ServiceController or WMI?

ACKNOWLEDGMENTS: Yes, I am talking about shutting down the physical UPS. I know how to stop the service. I figured this would be a common problem - I want my UPS to shut down from my PC. I had an idea that I'm going to try based on this page . You can see that APC (and everyone else) has to provide a DLL for the UPS service to call, and since the function calls are well documented there is no reason why I could not P / Invoke them. I'll edit this when I find out if it works.

Update: I tried to use UPSInit then UPSTurnOff and nothing happens. I did a little more work, but calling apcups.dll directly can be a dead end.

+1


source to share


3 answers


Ok, I have an answer (tested!), But it's not pretty. My APC UPS communicates using the APC "Smart" protocol ( more details here ). What you need in my case is the command "soft shutdown", "S". But first you need to make sure of this in the "Smart" ("Y") mode. Now if you want the Windows UPS service monitor to turn on, the service will have a hardware grip on the COM port. Thus, you can: a) let the Windows service shutdown the UPS, or b) kill the service and shutdown the UPS yourself.

The UPS itself has a "grace period" after it receives the "S" command, giving you time to shut down your OS. This means that in order to accomplish (a) above, you must:



  • Kill the utility (network).
  • Wait for the Windows UPS service to time out (default and minimum 2 minutes)
  • Wait for Windows to close - near the end, it will send the command "S"
  • Wait for the UPS to expire before it actually shuts down.

I think we're going to choose (a) only because (b) involves additional work killing the service and implementing serial communications.

+1


source


Check my comments to Herman, you want to turn off the UPS, not the UPS SERVICE, right? I mean, you want this thing to shut down, kill power, etc., right?

If so, you are looking at a UPS by UPS model. I doubt two of them will work the same.

If you are looking for a UPS, try "APC" or "battery". I think a lot of code is what works on laptops to deal with battery etc.



Some place is hidden in some dusty old files. I have information about the protocol for the APC UPS, as well as the commands they respond to and what they send to the PC, etc. But that was WAY the same day we used to connect our UPS to our computers with SERIAL cables ... you could actually talk to a UPS with Qmodem or Hyperterm ...

Found this out by talking to the guys at APC. They are very nice and helpful. For the time being, I think you just post the URL coming from your Powerchute software and it will talk directly to the UPS and execute your commands.

+2


source


Please tell me what language you are trying to do this in ... if you are using .NET you can do it using the ServiceController class (read the docs).

To manage services in Win32 API using C / C ++ Service Functions (Windows) .

For example, to stop a service, you can use the ControlService function like this (it's a quick and dirty example):

OpenService (hServMgr, TEXT("\\UPS_SERVICE_0"), SC_MANAGER_ALL_ACCESS);

SERVICE_STATUS stat;
ControlService (hUpsService, SERVICE_CONTROL_STOP, &stat)

      

Note that you need to provide a Service Manager descriptor in hServMgr, and the name \\ UPS_SERVICE_0 is the name that must match the required UPS service (either embedded Windows or otherwise).

Remember that you need appropriate security rights to stop the service. This is not a problem with the Adminstration account, but keep in mind what happens when you sign up with a non-admin account.

Hope it helps.

About turning off the physical UPS, I remember that in WIn98 days I was able to turn off the device by talking to the UPS through the COM port, although I don't remember the brand or how the programming interface was.

-1


source







All Articles