APC UPS for Home and Office Forum
Support forum to share knowledge about installation and configuration of APC offers including Home Office UPS, Surge Protectors, UTS, software and services.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
I have a unique problem in which a ups on power failure shuts windows down, but it seems to shut it down too fast. Faster than an app is able to save a database to a solid state drive. I was wondering if anyone knew the code that the ups uses to initiate the shutdown procedure and if it is changeable? I was able to narrow the problem to ups since a windows shutdown by all other means resulted in the database being saved. Only on ups power failure did shutdown rather expediently end all threads.
Does it use the ExitWindowsEx function I assume?
If so what are the values of the flags associated with this function?
Thank you
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:53 AM
I assume you're looking for USB API stuff? You might want to check out LibUSB (the Win32 port)... I've found it can make things easier.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
APC cannot provide proprietary code to customers, unfortunately.
Maybe if one of our other customers has dug into this issue in depth, they can provide some insight to the issue.
What version of our software are you using out of curiosity?
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
The BR series of Back-UPS UPS' are simple signaling which mean the UPS will only report events like low battery on battery, and UPS turnoff, and a limited amount of data on battery health and technical data, much of which Windows Native will not pick up.
You can try the BR1500 with PCBE agent in "Simple Signalling with any APC UPS" mode, but it's not an "officially supported" solution and you may find communication to be spotty.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
PowerChute Personal version 2.0 is in use. Didn't mean to step on any code legalities, just wanted to ascertain what exactly how the system(Back UPS RS 1500) manages and executes a shutdown due to power failure. The main configuration settings don't yield many options into the behavior of the event.
Are there any ways to control or coax the PowerChute program to allow threads to perhaps even certain threads to continue until they have run their course?
Perhaps is there a way to run my own shutdown exe or script file triggered by a power loss event? If I could set the configuration settings to use up power until only 5 minutes were left and run my script immediately on a power loss event then I'm sure the database would get saved.
Any registry keys that might be useful to modify? Or is the registry more or less off limits? Any config files open to being edited? or services that would be useful to look at?
Thanks
-Ryan Wilson
Applied Vision Corporation
Message was edited by: ryanshowseason2
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
What UPS are you using?
Scripting is only supported using our PCNS and PCBE software. You could try and get the PowerChute Business Edition agent working with your UPS, depending on the UPS model you have.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Back UPS RS 1500
I figure this isn't a compatible ups is it?
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Quick question: Does PCPE set off the alarms in windows - control panel - power options?
EDIT:
I've been looking around and realized that the system should be recognizing my ups as a battery. It does appear in the device manager as such. similarly as described here:
Link:[Answersboard | http://nam-en.apc.com/cgi-bin/nam_en.cfg/php/enduser/std_adp.php?p_faqid=2497&p_created=1025713924&p...]
But not as described I do not have the alarms tab and power meter tab. Instead I have the ups tab. Which doesn't seem to function correctly. I can go into selection and try to connect to my ups on com1 but it does not seem able to connect presumably because I am connecting by USB and not a COM port. With the options in the ups tab I believe I could reach a satisfactory solution, or if the alarms and power meter tab were existent like they are supposed to be I believe I could similarly reach a solution but they don't seem to work correctly...yet.
EDIT2:
Ok I got the connection to seemingly work between windows power options and the ups, but the actions I specified in the ups tab of power options do not seem to be executing. I have windows set to shutdown the system after 2 minutes on battery and the ups set to shut down the system after 3 minutes on ups. Windows doesn't seem to get any notifications however and the UPS shuts down the system instead. Perhaps the ups isn't sending windows anything...
Message was edited by: ryanshowseason2
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
I found out by accident that having powerchute personal installed was disabling all the windows settings I had implemented. Once I had uninstalled everything all those settings came into effect. For the record the shutdown mechanism there also forces all threads to immediately end as well. However its also possible to run your own program or script from the windows options so a quick batch file did the trick in shutting down properly allowing time for the database to do its thing.
I think I will still try the business edition install. The windows options aren't incredibly numerous and don't allow for set time periods before initiating shutdown, instead it activates while running under a specified percentage. For our applications plants might have numerous power outages. The battery may drop below that mark, the power may come back on. Then before the battery has had a chance to recharge above the pre specified point the power might go off again thereby immediately initiating an unnecessary shutdown for perhaps a power outage of only a few seconds.
Thanks for all the help though much appreciated.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
You can try the BR1500 with PCBE agent in "Simple Signalling with any APC UPS" mode, but it's not an "officially supported" solution and you may find communication to be spotty.
How does one put PCBE into simple signalling mode? I cannot seem to find the option anywhere... I'll start searching myself and hopefully update this answering my own question.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
when you install it, there should be an option to manually set up the UPS. when you do that it should ask for the signaling type - simple (or basic) or simple (or basic) with interface expander, then also an option to choose Back UPS (versus Smart UPS).
again this is when you start a clean install of powerchute BUSINESS edition agent.
also, did Erasmus mention you need the special cable for this to work? 940-0128 cable which is RJ45->DB9.
hope that helps!
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
I assume the RJ45 goes into the ups and db9 to the computer?
Also is there any way to know what the registry keys associated with PCPE do or would that also be considered under proprietary software?
Message was edited by: ryanshowseason2
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:47 AM . Last Modified: 2024-03-22 03:54 AM
yes, the RJ45 goes to the UPS data port and the DB9 goes to the computer.
and no, we cannot give any information dealing with the registry keys or anything like that 😕
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Thought if anyone else ever had a similar problem I'd post what I myself have done to alleviate the problem.
I've been able to uninstall the PCPE software and have the ups act as a battery under device manager. From there you can just set its low battery alarm to go off at 100% battery. Which in effect fires everytime the system goes on battery. You can set your own script in the same options, since I can do that I can run a simple batch file with a unforced shutdown which allows the system to shutdown normally and save our database. There are still problems with this however...
Unlike when PCPE shuts the system down the ups stays on battery and the motherboard never fully shuts off. So that and any other hardware attached that is still running (ie for us another ~100 watts) is still drawing from the battery. My guess is PCPE upon shutdown sends a signal to the ups to shut itself down after a sort of grace period regardless of what is still drawing power. If you can run a script you can run a program c, c++, c# whatever. If you can manage to send the same signal PCPE does you could probably get the same results, but I have not found out how. This would DEFINITELY fall under proprietary software I assume so no answers here. However I've found an open source apc ups software out there that claims to be able to do the same. Currently I'm dissecting this thing and think I've found the answer but I have to admit I'm not the best at converting linux/unix c++ to windows. Then I don't know if this forum would welcome me posting this sort of solution... Still if its allowed I'll post some code if I ever do find a solution.
Sorry if this post steps on the toes of the rules here. Just trying to help anyone else who comes down this path as it's taken the better part of 2 40 hour workweeks for me so far.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
you can certainly post anything you find here, as long as its not the proprietary APC software code.
is this APCUPSd you are working with?
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Yes it is. Currently I'm trying to find functions in the windows c++ api that perform the same operations as their driver c files modeled for linux. I accidentally converted code for dumb upses then realized we have a usb model and had to start over again.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
I ended up writing a simple script that delayed powerchute from shutting down until our program KaveMan.exe could complete its operations. This is done in VBS which is a scripting language supported by most windows versions now. If its not then its not hard to get the necessary files installed. If anyone else wants to use this be mindful of the version which is included in the registry key's path. Also make sure you change the name of the program to close and then in the SQL like query statement so you're searching for the same program to confirm if it has closed properly yet. Copy and paste this and name it whatever.vbs and bam you have a script to delay powerchute.
'_________________________________________CODE_________________________________________________
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
'check to see if on startup we've lost power
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "oot\default:StdRegProv")
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\UPSUtilityStatus"
strValueName = "ACPresent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
Wscript.Echo "Initial shutdown dialog check: " & dwValue
while true
'while the power is on just keep checking every second.
while dwValue = 1
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\UPSUtilityStatus"
strValueName = "ACPresent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
'Wscript.Echo "shutdown started: " & dwValue
WScript.sleep 1000
Wend
'power is now out set our current time
powerofftime = Timer
dwValue2 = 1 'this is our initial value to set to cancel shutdown, first we'll be cancelling shutdown
shuttingdown = false
'now check and see how much time powerchute is going to wait until shutdown
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\Settings"
strValueName = "Runtime when onbattery"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,powerchuteshutdown
powerchuteshutdown = ( powerchuteshutdown * 60 ) - 2'subtract 2 seconds so we get a little jump on them
'while the power is still out
while dwValue = 0
'check the power to see if it comes back on
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\UPSUtilityStatus"
strValueName = "ACPresent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
'keep setting cancel shutdown
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\Shutdown"
strValueName = "CancelShutdown"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue2
Wscript.Echo "shutdown started detected attempting to cancel"
'how many seconds have passed?
timepassed = Timer-powerofftime
'if already shutting down no need to go here again instead just keep checking power. Later might add support to restart genius in case of a last minute power restore
If shuttingdown = false Then
'if we're 2 seconds to powerchuteshutdown
If timepassed > powerchuteshutdown Then
Wscript.Echo "Power Grace Period ended killing kaveman"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "CMD /c TASKKILL /IM KaveMan.exe /T" 'kill kaveman
num = 1
while num > 0
Wscript.Echo "Kaveman still isn't dead! Beating down APC software until hes dead!"
'check to see if genius is off yet
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set service = locator.ConnectServer()
Set props = service.ExecQuery _
("select name, description from Win32_Process where name = 'KaveMan.exe'")
num = props.Count
'keep cancelling shutdown until genius is off
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\Shutdown"
strValueName = "CancelShutdown"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue2
Wend
dwValue2 = 0 'now we quit cancelling shutdown. Hopefully powerchute picks up on this and shuts the system down
shuttingdown = true
end if
end if
Wend
'if the power ever comes back on then we cancel all this and just go back to checking it every second
Wscript.Echo "Power is magically back! cancelling shutdown"
Wend
'_____________________________________END_CODE______________________________________________-
I do this by monitoring the ACpresent key which one of powerchute's processes constantly updates. Once power is out I retrieve the amount of time powerchute would have waited while setting the cancelshutdown key to stop them from shutting down. If power comes back on it cancels it all. If not by the grace period then I tell the important process to shutdown. Then continually check to see if it has ended yet. Once it has I stop setting cancel shutdown and powerchute does its thing. I dunno if this "technically" voids warranties or anything. It exists only for convenience.
EDIT: I can't seem to see the code correctly when I post....
Message was edited by: ryanshowseason2
null
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
'check to see if on startup we've lost power
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "oot\default:StdRegProv")
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\UPSUtilityStatus"
strValueName = "ACPresent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
Wscript.Echo "Initial shutdown dialog check: " & dwValue
while true
'while the power is on just keep checking every second.
while dwValue = 1
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\UPSUtilityStatus"
strValueName = "ACPresent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
'Wscript.Echo "shutdown started: " & dwValue
WScript.sleep 1000
Wend
'power is now out set our current time
powerofftime = Timer
dwValue2 = 1 'this is our initial value to set to cancel shutdown, first we'll be cancelling shutdown
shuttingdown = false
'now check and see how much time powerchute is going to wait until shutdown
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\Settings"
strValueName = "Runtime when onbattery"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,powerchuteshutdown
powerchuteshutdown = ( powerchuteshutdown * 60 ) - 2'subtract 2 seconds so we get a little jump on them
'while the power is still out
while dwValue = 0
'check the power to see if it comes back on
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\UPSUtilityStatus"
strValueName = "ACPresent"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
'keep setting cancel shutdown
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\Shutdown"
strValueName = "CancelShutdown"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue2
Wscript.Echo "shutdown started detected attempting to cancel"
'how many seconds have passed?
timepassed = Timer-powerofftime
'if already shutting down no need to go here again instead just keep checking power. Later might add support to restart genius in case of a last minute power restore
If shuttingdown = false Then
'if we're 2 seconds to powerchuteshutdown
If timepassed > powerchuteshutdown Then
Wscript.Echo "Power Grace Period ended killing kaveman"
Set oShell = CreateObject("WScript.Shell")
oShell.Run "CMD /c TASKKILL /IM KaveMan.exe /T" 'kill kaveman
num = 1
while num > 0
Wscript.Echo "Kaveman still isn't dead! Beating down APC software until hes dead!"
'check to see if genius is off yet
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set service = locator.ConnectServer()
Set props = service.ExecQuery _
("select name, description from Win32_Process where name = 'KaveMan.exe'")
num = props.Count
'keep cancelling shutdown until genius is off
strKeyPath = "SOFTWARE\APC\APC PowerChute Personal Edition\2.00.000\Shutdown"
strValueName = "CancelShutdown"
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue2
Wend
dwValue2 = 0 'now we quit cancelling shutdown. Hopefully powerchute picks up on this and shuts the system down
shuttingdown = true
end if
end if
Wend
'if the power ever comes back on then we cancel all this and just go back to checking it every second
Wscript.Echo "Power is magically back! cancelling shutdown"
Wend
hmm forum software doesn't seem to like my prog. I can email it if anyone is interested in the future ryanshowseason2 at gmail dot com
Message was edited by: ryanshowseason2
Message was edited by: ryanshowseason2
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Clever
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:54 AM
Ah yes for anyone who cares heres more or less the same program in c++
// UPS Monitor.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream.h"
#include "Windows.h"
#include "time.h"
int main(int argc, char* argv[])
{
while ( true )
{
DWORD dwVersion = 1;
HKEY hKey;
LONG returnStatus;
DWORD dwType = REG_DWORD;
DWORD dwSize = sizeof(DWORD);
while( dwVersion == 1)
{
//check the power
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\UPSUtilityStatus" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
returnStatus = RegQueryValueEx( hKey, TEXT( "ACPresent" ), NULL, &dwType,(LPBYTE)&dwVersion, &dwSize );
if ( returnStatus == ERROR_SUCCESS )
{
if ( dwVersion == 0)
cout << "Power lost!";
dwVersion = 0;
}
}
//Wait a second or two. Don't want to cut in on too much processing time
Sleep( 1000 );
}
//retrieve the runtime for the ups from apc registry key
DWORD batteryRuntime;
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\Settings" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
returnStatus = RegQueryValueEx( hKey, TEXT( "Runtime when onbattery" ), NULL, &dwType,(LPBYTE)&batteryRuntime, &dwSize );
if ( returnStatus == ERROR_SUCCESS )
{
}
}
//Get our current time to check against
time_t powerOffTime;
powerOffTime = time (NULL);
DWORD cancelShutdown = 1;
while( dwVersion == 0 )//while the power is still off
{
//First check the power
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\UPSUtilityStatus" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
returnStatus = RegQueryValueEx( hKey, TEXT( "ACPresent" ), NULL, &dwType,(LPBYTE)&dwVersion, &dwSize );
}
//next set cancel shutdown
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\Shutdown" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
RegSetValueEx( HKEY_LOCAL_MACHINE, TEXT( "CancelShutdown" ), 0L, dwType, (LPBYTE)&cancelShutdown, dwSize );
}
//check if the time has run over
time_t currentTime;
currentTime = time (NULL);
if( ( currentTime - powerOffTime ) >= batteryRuntime )
{
//if it has send the message to shutdown genius
HWND genius = FindWindowEx( NULL, NULL, "#32770", "Genius" );//this is the program Im closing down and waiting on
SendMessage( genius, WM_QUERYENDSESSION, NULL, NULL );
//determine if genius is still running
genius = FindWindowEx( NULL, NULL, "#32770", "Genius" );
while( dwVersion == 0 && genius != NULL )//while the power is still off and genius isn't done yet
{
//next set cancel shutdown
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\Shutdown" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
RegSetValueEx( HKEY_LOCAL_MACHINE, TEXT( "CancelShutdown" ), 0L, dwType, (LPBYTE)&cancelShutdown, dwSize );
}
//determine if genius is still running
genius = FindWindowEx( NULL, NULL, "#32770", "Genius" );
//retrieve acpresent
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\UPSUtilityStatus" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
returnStatus = RegQueryValueEx( hKey, TEXT( "ACPresent" ), NULL, &dwType,(LPBYTE)&dwVersion, &dwSize );
}
}
}
cancelShutdown = 0;
//next stop cancelling shutdown
returnStatus = RegOpenKeyEx( HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\APC\\APC PowerChute Personal Edition\\1.04.000\\Shutdown" ), 0L, KEY_ALL_ACCESS, &hKey );
if ( returnStatus == ERROR_SUCCESS )
{
RegSetValueEx( HKEY_LOCAL_MACHINE, TEXT( "CancelShutdown" ), 0L, dwType, (LPBYTE)&cancelShutdown, dwSize );
}
//wait 20 seconds. By this time if ac was off apc should've killed everything. If not check the AC
Sleep( 20000 );
//restart genius
}
//power is back loop back to the top and keep checking acpresent
}
return 0;
}
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:53 AM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:53 AM
Well for anyone who ever looks at this thread again unfortunately the code I had has been lost. It never went into our product as it was very hacky. The knowledge of what was going on is still in this thread although I don't remember exact details.
The ACPresent registry key was for lack of a better term the "key" to solving the issue myself. Watching it until it was set and then hammering on the cancelshutdown key until my programs were ready.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:53 AM
oh, you're over my head now 😉
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-06-29 12:48 AM . Last Modified: 2024-03-22 03:53 AM
I assume you're looking for USB API stuff? You might want to check out LibUSB (the Win32 port)... I've found it can make things easier.
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.