472,331 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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 2169
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
5
by: Niloday | last post by:
Hi All, I am trying to access a mapped network drive from a service that I have created. The service needs to create/delete folders/files on a...
1
by: Z0gS | last post by:
I got this problem for the web application I try to access files on a remote server. string dirs = Directory.GetDirectories(@"E:\vehicles") E...
3
by: Bonj | last post by:
I need to write a windows service, and the only way it can access a shared drive on a file server on the network is if the installer is put in...
6
by: Bijesh | last post by:
Hi All, I've developed a Windows Service that acts as a remoting server (.NET Remoting). The client(user) is able to connect to the server and...
3
by: Tom Lant | last post by:
Hello everybody, I have been developing an application in Visual Basic.Net that queries an SQL database every 15 minutes. My problem arises when...
0
by: Dennis | last post by:
I have tried to use the IWshRuntimeLibrary and ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk") to get all Logical Drives, Mapped...
2
by: Ian Murrell | last post by:
My application writes a text data file to a folder on another computer. The other computer is mapped by drive letter to the root (C) shared folder,...
1
by: 4johnny | last post by:
I have a small office (in a workgroup environment not a domain) that has a number of DBs that reside on one XP PC and shared for everyone to use. ...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.