469,890 Members | 2,316 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

Accessing shared network drives prevents standby mode

JT
Hi,

I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. Not going into standby is a very good thing for
my application, but I don't want users to be required to share a drive
and file just to accomplish this.

I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
would accomplish what I need. I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).

Is there a managed code way to accomplish this? Does anyone have any
suggestions?

Thanks,

JT
Feb 18 '08 #1
6 2059
JT,

You ^might^ be able to do this through the WMI provider for windows,
which means you would access the System.Management namespace, but to be
honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
The declaration for the function is at:

http://www.pinvoke.net/default.aspx/...tionState.html

Also, you don't need unsafe code to call this. But a call through the
P/Invoke layer is required. In this case though, it's trivial. Some
sections of the .NET framework are completely reliant on the P/Invoke layer
(pretty much everything in the System.Windows.Forms namespace).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JT" <jt@onemain.comwrote in message
news:a6**********************************@e6g2000p rf.googlegroups.com...
Hi,

I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. Not going into standby is a very good thing for
my application, but I don't want users to be required to share a drive
and file just to accomplish this.

I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
would accomplish what I need. I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).

Is there a managed code way to accomplish this? Does anyone have any
suggestions?

Thanks,

JT
Feb 18 '08 #2
JT
Thanks Nicholas,

Before my first post I did a quick scan through WMI, and quickly got
lost, never having looked at it before, but I didn't see anything
relating to what I need. I will go look at your link and investigate
P/Invoke. I've never dealt with that either.

JT

On Feb 18, 11:48*am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
JT,

* * You ^might^ be able to do this through the WMI provider for windows,
which means you would access the System.Management namespace, but to be
honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
The declaration for the function is at:

http://www.pinvoke.net/default.aspx/...ExecutionState....

* * Also, you don't need unsafe code to call this. *But a call through the
P/Invoke layer is required. *In this case though, it's trivial. *Some
sections of the .NET framework are completely reliant on the P/Invoke layer
(pretty much everything in the System.Windows.Forms namespace).

--
* * * * * - Nicholas Paldino [.NET/C# MVP]
* * * * * - m...@spam.guard.caspershouse.com

"JT" <j...@onemain.comwrote in message

news:a6**********************************@e6g2000p rf.googlegroups.com...
Hi,
I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. *Not going into standby is a very good thing for
my application, but I don't want users to be required to share a drive
and file just to accomplish this.
I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
would accomplish what I need. *I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).
Is there a managed code way to accomplish this? *Does anyone have any
suggestions?
Thanks,
JT- Hide quoted text -

- Show quoted text -
Feb 18 '08 #3
JT
Nicholas,

I just did my first P/Invoke and it works like a champ (on preliminary
evaluation)! Are there any caveats about P/Invokes?

Thanks,

JT

On Feb 18, 12:07*pm, JT <j...@onemain.comwrote:
Thanks Nicholas,

Before my first post I did a quick scan through WMI, and quickly got
lost, never having looked at it before, but I didn't see anything
relating to what I need. *I will go look at your link and investigate
P/Invoke. *I've never dealt with that either.

JT

On Feb 18, 11:48*am, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guard.caspershouse.comwrote:
JT,
* * You ^might^ be able to do this through the WMI provider for windows,
which means you would access the System.Management namespace, but to be
honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
The declaration for the function is at:
http://www.pinvoke.net/default.aspx/...ExecutionState....
* * Also, you don't need unsafe code to call this. *But a call through the
P/Invoke layer is required. *In this case though, it's trivial. *Some
sections of the .NET framework are completely reliant on the P/Invoke layer
(pretty much everything in the System.Windows.Forms namespace).
--
* * * * * - Nicholas Paldino [.NET/C# MVP]
* * * * * - m...@spam.guard.caspershouse.com
"JT" <j...@onemain.comwrote in message
news:a6**********************************@e6g2000p rf.googlegroups.com...
Hi,
I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. *Not going into standby is a very good thing for
my application, but I don't want users to be required to share a drive
and file just to accomplish this.
I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
would accomplish what I need. *I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).
Is there a managed code way to accomplish this? *Does anyone have any
suggestions?
Thanks,
JT- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
Feb 18 '08 #4
Keep in mind that calling this API doesn't prevent a *user* to put the
system in Sleep state.

Willy.
"JT" <jt@onemain.comwrote in message
news:94**********************************@d4g2000p rg.googlegroups.com...
Nicholas,

I just did my first P/Invoke and it works like a champ (on preliminary
evaluation)! Are there any caveats about P/Invokes?

Thanks,

JT

On Feb 18, 12:07 pm, JT <j...@onemain.comwrote:
Thanks Nicholas,

Before my first post I did a quick scan through WMI, and quickly got
lost, never having looked at it before, but I didn't see anything
relating to what I need. I will go look at your link and investigate
P/Invoke. I've never dealt with that either.

JT

On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"

<m...@spam.guard.caspershouse.comwrote:
JT,
You ^might^ be able to do this through the WMI provider for windows,
which means you would access the System.Management namespace, but to be
honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
The declaration for the function is at:
http://www.pinvoke.net/default.aspx/...ExecutionState....
Also, you don't need unsafe code to call this. But a call through the
P/Invoke layer is required. In this case though, it's trivial. Some
sections of the .NET framework are completely reliant on the P/Invoke
layer
(pretty much everything in the System.Windows.Forms namespace).
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"JT" <j...@onemain.comwrote in message
news:a6**********************************@e6g2000p rf.googlegroups.com...
Hi,
I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. Not going into standby is a very good thing for
my application, but I don't want users to be required to share a drive
and file just to accomplish this.
I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
would accomplish what I need. I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).
Is there a managed code way to accomplish this? Does anyone have any
suggestions?
Thanks,
JT- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -


Feb 18 '08 #5
JT
Hey Willy,

I've given the user a preference setting to let him decide how he
wants the application to behave. I figure if he's set it so that it
will not go into full standby, then if he purposely places it in that
mode, he has a reason for it. The application doesn't crash if it's
in standby.

So what would a user do to cause standby mode when the application
setting has indicated otherwise?

JT

On Feb 18, 2:00*pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
Keep in mind that calling this API doesn't prevent a *user* to put the
system in Sleep state.

Willy.

"JT" <j...@onemain.comwrote in message

news:94**********************************@d4g2000p rg.googlegroups.com...
Nicholas,

I just did my first P/Invoke and it works like a champ (on preliminary
evaluation)! *Are there any caveats about P/Invokes?

Thanks,

JT

On Feb 18, 12:07 pm, JT <j...@onemain.comwrote:
Thanks Nicholas,
Before my first post I did a quick scan through WMI, and quickly got
lost, never having looked at it before, but I didn't see anything
relating to what I need. I will go look at your link and investigate
P/Invoke. I've never dealt with that either.
JT
On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
JT,
You ^might^ be able to do this through the WMI provider for windows,
which means you would access the System.Management namespace, but to be
honest, doing it through the P/Invoke layer is ^not^ that big of a deal.
The declaration for the function is at:
>http://www.pinvoke.net/default.aspx/...ExecutionState.....
Also, you don't need unsafe code to call this. But a call through the
P/Invoke layer is required. In this case though, it's trivial. Some
sections of the .NET framework are completely reliant on the P/Invoke
layer
(pretty much everything in the System.Windows.Forms namespace).
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"JT" <j...@onemain.comwrote in message
>news:a6**********************************@e6g2000 prf.googlegroups.com....
Hi,
I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. Not going into standby is a very good thing for
my application, but I don't want users to be required to share a drive
and file just to accomplish this.
I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD values),
would accomplish what I need. I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).
Is there a managed code way to accomplish this? Does anyone have any
suggestions?
Thanks,
JT- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
Feb 18 '08 #6
"JT" <jt@onemain.comwrote in message
news:b5**********************************@i29g2000 prf.googlegroups.com...
Hey Willy,

I've given the user a preference setting to let him decide how he
wants the application to behave. I figure if he's set it so that it
will not go into full standby, then if he purposely places it in that
mode, he has a reason for it. The application doesn't crash if it's
in standby.
The API only prevents the system to go into standby mode or turn the monitor
off when triggered by the "power mode policy" settings. This doesn't prevent
the user from manually putting the system in standby mode.

So what would a user do to cause standby mode when the application
setting has indicated otherwise?

Start menu - Sleep or Press the Sleep or the Power button when configured
to put the system in Sleep state.

JT

On Feb 18, 2:00 pm, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
Keep in mind that calling this API doesn't prevent a *user* to put the
system in Sleep state.

Willy.

"JT" <j...@onemain.comwrote in message

news:94**********************************@d4g2000p rg.googlegroups.com...
Nicholas,

I just did my first P/Invoke and it works like a champ (on preliminary
evaluation)! Are there any caveats about P/Invokes?

Thanks,

JT

On Feb 18, 12:07 pm, JT <j...@onemain.comwrote:
Thanks Nicholas,
Before my first post I did a quick scan through WMI, and quickly got
lost, never having looked at it before, but I didn't see anything
relating to what I need. I will go look at your link and investigate
P/Invoke. I've never dealt with that either.
JT
On Feb 18, 11:48 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
JT,
You ^might^ be able to do this through the WMI provider for windows,
which means you would access the System.Management namespace, but to
be
honest, doing it through the P/Invoke layer is ^not^ that big of a
deal.
The declaration for the function is at:
>http://www.pinvoke.net/default.aspx/...ExecutionState....
Also, you don't need unsafe code to call this. But a call through the
P/Invoke layer is required. In this case though, it's trivial. Some
sections of the .NET framework are completely reliant on the P/Invoke
layer
(pretty much everything in the System.Windows.Forms namespace).
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"JT" <j...@onemain.comwrote in message
>news:a6**********************************@e6g2000 prf.googlegroups.com...
Hi,
I've realized that my good fortune of not having my computer go into
standby mode was the result of my application accessing a file on a
shared network drive. Not going into standby is a very good thing
for
my application, but I don't want users to be required to share a
drive
and file just to accomplish this.
I've read in old posts in various places stating that by importing
kernel32.dll I could access a function called
SetThreadExecutionState(...) with a value of ES_SYSTEM_REQUIRED,
potentially ORed with ES_CONTINUOUS (or the equivalent DWORD
values),
would accomplish what I need. I'm guessing this is not managed code
and would have to be marshalled in and used as unsafe code (please
forgive me for not knowing anything about marshalling or unmanaged
code).
Is there a managed code way to accomplish this? Does anyone have any
suggestions?
Thanks,
JT- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -


Feb 18 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Cherrish Vaidiyan | last post: by
3 posts views Thread by Bonj | last post: by
3 posts views Thread by Tom Lant | last post: by
1 post views Thread by 4johnny | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.