Click here to Skip to main content
14,427,367 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Everybody,

As a part of a tool I list the drives that are available on several workstations, including a number of properties. Since in my particular case it's accessing remote workstations over the network, I'm using WMI (a ManagementObjectCollection), but my question would as well arise if I were using the 'IsReady' property of a DriveInfo object.

In order to avoid runtime errors, I'm checking the 'IsReady' status of each drive before retrieving it's properties. Some of the SATA HDDs, however, seem to enter some kind of 'sleep' status after a while of inactivity – thus return 'FALSE' to the function, despite being available and accessible. As a result, the drive's properties are not listed.

How can I triger something like a'wake up call' in my code? My only idea would be to catch the error, wait for some seconds and try 'IsReady' again... it just seems really clumsy to me. Any advice is highly appreciated!

Kind regards

What I have tried:

After manually 'waking up' the relevant drives (e.g. by opening an Explorer window) 'IsReady' returns TRUE and – after a re-start of the tool – the code can retrieve the drive's properties.
Updated 15-Jan-20 3:59am
Richard MacCutchan 15-Jan-20 8:20am
The Power settings tool in Control Panel allows you to switch off (i.e. sleep) the hard drive after a period of inactivity. Users may set this value to anything they wish.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The problem is not trying to wake up the drive. You have to wake up Windows.

Try checking out the technique in Wake the PC from standby or hibernation[^].
Sonhospa 15-Jan-20 9:20am
Thank you, Dave. However, it must be something drive-specific as on the same machine e.g. 4 drives are reported TRUE (IsReady) while 2 others aren't - at least not before waking them up manually.
Dave Kreskowiak 15-Jan-20 10:20am
and how do you "wake them up manually"?
Sonhospa 15-Jan-20 10:43am
For example by opening an Explorer window (Network list -> server name -> drive letter)
Dave Kreskowiak 15-Jan-20 15:41pm
So you've got drives that go to sleep even when a user is working around in Windows? That's weird.
Sonhospa 17-Jan-20 12:45pm
Hi Dave, sorry for the delayed response. It may seem weird but is still true - only for some SATA drives. If a user accesses the particular HDD, it takes a few seconds to 'wake up' from some kind of standby-mode I suspect. As mentioned, after waking up I get 'IsReady = TRUE'.
Dave Kreskowiak 17-Jan-20 16:05pm
I have no idea how to wake them up by code.
Sonhospa 18-Jan-20 5:41am
Thank you, though!
Ralf Meier 3 days ago
when reading all the responses my idea is that you first try to read the directory (for example) of this drive. I suppose that the Windows-Explorer does something like this. But of course you have to check for exeptions because it is possible that you can't get the drive ready. Also when trying to access Network-drives it is possible that you get a very long Timeout for every answer (if the drive isn't ready).
I know that this isn't something like a Solution ... but perhaps an idea to go a step ahead ...
Sonhospa 3 days ago
Thank you, Ralf. As written in my first post, I had the same idea but found it a little bit clumsy ("...von hinten durch die Brust ins Auge" ;-) sozusagen). I hoped someone would have a more elegant solution. Have a nice evening!
Dave Kreskowiak 3 days ago
The problem with reading the directory to wake up the drive is what if you get the directory from the cache either in NTFS or on the drive instead of the drive spinning up to read it direct from disk?
Ralf Meier 2 days ago
Hi Dave,
I don`t understand what you mean with your comment - could you explain it once more ...?
Dave Kreskowiak 2 days ago
Windows keeps some of the file system structures in memory, cached.

The directory read may end up being retrieved from the cached copy instead of the drive.

But, if it's not cached in memory, Windows will go to the drive to get the directory information. Well, spinning-rust drives have cache memory on them too. You could just as easily end up reading the directory you're trying to wake up the drive with from the drives cache.

You have to get through two caches before you get to the platters and trigger them to spin up.
Ralf Meier yesterday
I made this suggestion because some years ago I had the issue to store data from a HMI-System, which was connected to a PLC (both Siemens), to a Network-Drive. Sometimes the Network-Drive was not accessible but Windows doesn't realized that (perhaps because of cached information). With programming I only had the possibilities of VBA. A normal write-access to the Network-Drive causes a very long Timeout which wasn't akceptable - but the directory-read in this environment causes an error which was handlebar for me inside the Script. But additional : I tried to read the directory from a defined subdirectory - not from the root ...
Ralf Meier 2 days ago
"von hinten durch die Brust ins Auge" is a sentence which is normally used by me - should it be possible that we know each other in person ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100