473,320 Members | 1,600 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,320 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 2251
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 steps in this site : ...
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 network drive. When I tried to connect to 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 drive is a map to a network drive. I get the...
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 "User" mode - "LocalService", "LocalSystem" and...
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 start a program by giving the executable path of...
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 the computer upon which the application is...
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 Network Drives, Shared Folders and Shared Drives with...
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, eg as G:. The network is simple peer2peer, shared...
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. All users have mapped drives to this share and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.