473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Avoid standby under vista with c# ?

Hi i'm searching a solution to avoid that the user can go in the standby
mode while a app is runing.

i have searched and readed a lot in the web and have not found a working
solution...
for the moment i use "away mode" under vista to get simiar results but with
other handycaps like screen off etc. :-(
i have get this code from a other dev but it doesnt work with vista, the pc
its going directly in the standby mode.

------------------------------------------
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MonitorSleepPrevent
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern EXECUTION_STATE SetThreadExecutionState(
EXECUTION_STATE flags);

[Flags]
public enum EXECUTION_STATE : uint
{
ES_SYSTEM_REQUIRED = 0x00000001,
ES_DISPLAY_REQUIRED = 0x00000002,
// ES_USER_PRESENT = 0x00000004,
ES_CONTINUOUS = 0x80000000
}

void PreventMonitorPowerdown()
{
SetThreadExecutionState( EXECUTION_STATE.ES_DISPLAY_REQUIRED |
EXECUTION_STATE.ES_CONTINUOUS);
}

void AllowMonitorPowerdown()
{
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINU OUS);
}

private void Form1_Load(object sender, EventArgs e)
{
PreventMonitorPowerdown();
}
}
}
------------------------------------------

please help me to get a working solution for that

what i need is:

if the app is running and the user is pressing the power button (standby) or
uses the start\shutdown(standby) menu the pc should still on.

thank you for any tips
Volkan

Jun 27 '08 #1
7 3489
On Wed, 21 May 2008 07:01:36 -0700, Volkan Senguel <mo******@2wire.ch>
wrote:
[...]
if the app is running and the user is pressing the power button
(standby) or
uses the start\shutdown(standby) menu the pc should still on.
I'm not convinced you can do this. The OS provides ways for an
application to tell it not to go into standby/hibernate/screen-saver
automatically. But if the user explicitly commands that, I don't think
there's much you can do about that. Ultimately, the OS needs to respect
the user's wishes.

Pete
Jun 27 '08 #2
Sure i know that, but in Windows XP was possible to avoid the standby mode
by a application so that the user can not force the standby... only shutdown
etc...

Under Vista does this not work because Vista doesnt broadcast the suspend
message anymore, and by changing the SetThreadExecutionState does not work
:-(

Infos from Microsoft:
http://download.microsoft.com/downlo...plications.ppt

Windows Vista will not query user mode components when entering sleep
PBT_APMQUERYSUSPEND event will not be sent

Windows Vista will continue to notify user mode components when entering
sleep
PBT_APMSUSPEND event is sent
Timeout has been reduced from 20s to 2s
Use this event to do limited cleanup before the suspend transition
Realy i dont know how to handle this because we have a multimedia app which
works flawless under xp, users can record and not go into standby while
reording is in progress.
Under Vista, user goes to standby and the recording are lost (!)

thats the reason why i need a working solution for that.

thank you
Volkan
"Peter Duniho" <Np*********@nnowslpianmk.comschrieb im Newsbeitrag
news:op***************@petes-computer.local...
On Wed, 21 May 2008 07:01:36 -0700, Volkan Senguel <mo******@2wire.ch>
wrote:
>[...]
if the app is running and the user is pressing the power button
(standby) or
uses the start\shutdown(standby) menu the pc should still on.

I'm not convinced you can do this. The OS provides ways for an
application to tell it not to go into standby/hibernate/screen-saver
automatically. But if the user explicitly commands that, I don't think
there's much you can do about that. Ultimately, the OS needs to respect
the user's wishes.

Pete

Jun 27 '08 #3
Heh, dont eaven know what that is..
>PBT_APMSUSPEND event is sent
Timeout has been reduced from 20s to 2s
Use this event to do limited cleanup before the suspend transition
Just a thought, why not send a keystroke from the program, "left/right
shift pressed" to avoid that (watch out for KVM:s timeout) ... a timer
and ... voila...

Or, too stupid approach? I use KISS, so Keep It Simple Stupid ;) so
dont use it.

//CY
Jun 27 '08 #4
On Wed, 21 May 2008 11:48:27 -0700, Volkan von Klass <mo******@2wire.ch>
wrote:
Sure i know that, but in Windows XP was possible to avoid the standby
mode by a application so that the user can not force the standby... only
shutdown etc...

[...]

Realy i dont know how to handle this because we have a multimedia app
which works flawless under xp, users can record and not go into standby
while reording is in progress.
Under Vista, user goes to standby and the recording are lost (!)
I really don't understand what you're saying.

If you mean that Vista itself is automatically trying to go into standby
mode, and you're unable to prevent that, then yes...I agree there should
be an API in the OS that allows that, and frankly the existing one that
works in XP ought to work in Vista too.

But if you mean that you can in XP prevent the system from going into
standby even when the user has explicitly told it to, and that you're
disappointed that that no longer works in Vista, well... My opinion is
that the XP behavior was a bug, and I'm happy to hear they fixed it in
Vista.

If the latter scenario is what you're talking about, the solution is to
tell your users to stop putting the system into standby mode when they are
trying to use the computer record.

If the former, I would report it as a bug against Vista
(http://connect.microsoft.com/), as well as contact Microsoft through
their support web site (http://support.microsoft.com/) and file a support
request against Vista. I have found that on occasion, filing a support
request results in a confirmation of the bug as well as help to work
around the problem.

Pete
Jun 27 '08 #5


"Peter Duniho" wrote:
On Wed, 21 May 2008 11:48:27 -0700, Volkan von Klass <mo******@2wire.ch>
wrote:
Sure i know that, but in Windows XP was possible to avoid the standby
mode by a application so that the user can not force the standby... only
shutdown etc...

[...]

Realy i dont know how to handle this because we have a multimedia app
which works flawless under xp, users can record and not go into standby
while reording is in progress.
Under Vista, user goes to standby and the recording are lost (!)

I really don't understand what you're saying.

If you mean that Vista itself is automatically trying to go into standby
mode, and you're unable to prevent that, then yes...I agree there should
be an API in the OS that allows that, and frankly the existing one that
works in XP ought to work in Vista too.

But if you mean that you can in XP prevent the system from going into
standby even when the user has explicitly told it to, and that you're
disappointed that that no longer works in Vista, well... My opinion is
that the XP behavior was a bug, and I'm happy to hear they fixed it in
Vista.

If the latter scenario is what you're talking about, the solution is to
tell your users to stop putting the system into standby mode when they are
trying to use the computer record.

If the former, I would report it as a bug against Vista
(http://connect.microsoft.com/), as well as contact Microsoft through
their support web site (http://support.microsoft.com/) and file a support
request against Vista. I have found that on occasion, filing a support
request results in a confirmation of the bug as well as help to work
around the problem.

Pete
I came across searching for a solution similar to the scenario that volkan
describes and hi is absotut right.

Think of an htpc with multiple tuners: the user schedules recordings and
used the system for watching live tv. If the user finished watching live tv
he/she uses the remote to power of the system, regardless of backround
recordings in process . Now its up to the software to keep the system alive
until the recording is finished.
Jun 27 '08 #6
On Thu, 22 May 2008 13:54:01 -0700, Joerg
<Jo***@discussions.microsoft.comwrote:
[...]
Think of an htpc with multiple tuners: the user schedules recordings and
used the system for watching live tv. If the user finished watching live
tv
he/she uses the remote to power of the system, regardless of backround
recordings in process . Now its up to the software to keep the system
alive
until the recording is finished.
We'll just have to agree to disagree. IMHO, if you're making an HTPC with
a remote that is directly hooked to the stand-by functionality of Windows,
that's a design bug and it's better addressed by fixing the way the remote
deals with the system than by trying to work around a fundamentally
correct behavior in the OS.

Pete
Jun 27 '08 #7
I came across searching for a solution similar to the scenario that volkan
describes and hi is absotut right.

Think of an htpc with multiple tuners: the user schedules recordings and
used the system for watching live tv. If the user finished watching live
tv
he/she uses the remote to power of the system, regardless of backround
recordings in process . Now its up to the software to keep the system
alive
until the recording is finished.
Thank you joerg, thats exactly what i mean.

the user doesnt handle this with his remote control or simulating any
keystrokes etc....

the system must stay online.

in windows xp was a feature that the system cant suspend, in vista,
microsoft changed this behaviour because a lot of developers had not used
corectly this feature.

any way

has any one a solution for that?

thank you for the help
Volkan
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mahesh Hardikar | last post by:
Hi , Oracle 8.1.7.0.0 on HP-UX 11.0 EMC2 Disk Array We are in a process of implementing DR Site using Standby Database feature of Oracle. We have tested it on 2 NT machines here & things are...
0
by: Cherrish Vaidiyan | last post by:
hello, Thanx for the suggestions on my Listener query. Now i am performing a simple work.. STANDBY DATABASE creation. I have followed the instraction from Oracle 9i Release 1 documentation...
0
by: Cherrish Vaidiyan | last post by:
sir, The following are the steps that i followed in setting up standby database on Red hat Linux 9. i am using Oracle 9i. i have followed the steps in this site : ...
6
by: shorti | last post by:
db2 8.1 fix pack 12 on AIX 5.3 This is a newly configured HADR machine. The HADR was up and running. I was 'playing' around some on the standby and did a db2 deactivate and things sort of went...
56
by: Squishy | last post by:
I tried installing my VS2005 Pro on Vista Ultimate 32 bit RTM today and got errors stating that VS2005 was not compatible with Vista. Microsoft......please pull your finger out of my ass and tell...
2
by: paul | last post by:
Hi, I have two databases in hadr, this morning i issued a "takeover ... by force" because the normal takeover didn't worked. Now i have two standard databases, and if i try to put the old primary...
0
by: Vinod Sadanandan | last post by:
STANDBY DATABASE MONITORING & PROTECION MODES (9iR2) This document is written for understanding and monitoring standby database configured with diffrent protection modes . MAXIMUM PROTECTION ...
4
by: Mark A | last post by:
I would like to make a split mirror copy of a HADR standby database. Please note that I do not want to create a standby with a split mirror of the primary, but I want to make a split mirror of the...
0
by: Peter Van Peborgh | last post by:
I have an app that is built in Access 2002 and packaged with its runtime. When installing it in a Vista PC/laptop, several dialog boxes pop up that require specific answers for the app to install and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.