This is an improved script of @Alexandru's for Windows.
EDIT: Windows 8 will not properly run scripts with spaces in their names, it keeps asking for the program to open with at each and every execution. Spaces and quotation marks have been removed from file names and version bumped to 1.01.
Save as KeepAwake101.wsf
:
<?xml version="1.0" encoding="utf-8"?>
<package>
<job id="keepAwake">
<?job error="false" debug="false"?>
<script>
//<![CDATA[
/*
* Copyright 2012 XP1
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*jslint browser: true, vars: true, white: true, maxerr: 50, indent: 4 */
(function (script, shell, fileSystem)
{
"use strict";
var currentDirectory = fileSystem.getFolder(shell.currentDirectory);
currentDirectory.createTextFile("empty.txt", true, false).close();
script.quit();
}(this.WScript, new this.ActiveXObject("WScript.Shell"), new this.ActiveXObject("Scripting.FileSystemObject")));
//]]>
</script>
</job>
</package>
This script creates an empty file at the root of the current directory.
Next, save this XML file as KeepAwake101.xml
:
<?xml version="1.0" encoding="utf-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2012-01-01T00:00:01</Date>
<Author>Administrator</Author>
</RegistrationInfo>
<Triggers>
<BootTrigger>
<Repetition>
<Interval>PT20M</Interval>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<ExecutionTimeLimit>PT30S</ExecutionTimeLimit>
<Enabled>true</Enabled>
</BootTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<GroupId>Users</GroupId>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT30S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>\KeepAwake101.wsf</Command>
<WorkingDirectory>L:\</WorkingDirectory>
</Exec>
</Actions>
</Task>
When you save the XML file, make sure that you save the file encoding as UTF-16 (labeled "Unicode" in Notepad).
On <Command>"\KeepAwake101.wsf"</Command>
, make sure that you modify this line by adding the location of the script.
On <WorkingDirectory>L:\</WorkingDirectory>
, you can change this line to the location of your drive.
Start > All Programs > Accessories > Right click on "Command Prompt" > Run as administrator.
Change to the directory where the XML file is located.
Import the XML as a task:
schtasks /create /tn "Keep Awake 1.01" /xml "KeepAwake101.xml"
If you want to delete the task, type:
schtasks /delete /tn "Keep Awake 1.01" /f
This task is set up to run every 20 minutes. My Western Digital Elements 2 TB (WDBAAU0020HBK) external hard drive sleeps every 30 minutes.
After you have imported the task, you can configure the interval and schedule by using the task scheduler. To open the task scheduler, in the command prompt or in a Start > Run dialog, type:
taskschd.msc
Warning:
Western Digital Green drives may have an aggressive IntelliPark feature that parks the head after 8 seconds of inactivity. This will cause the load/unload cycle count (LCC) to increase substantially. You can check the LCC by using software, such as Defraggler or Hard Disk Sentinel on Windows, that can read S.M.A.R.T. data.
Keeping the drive awake every 20 minutes may eventually increase the LCC over the limit. Instead of running this script, you may consider only using the drive occasionally and leaving it unplugged.
You can read more here:
http://www.sagaforce.com/~sound/wdantiparkd/
Although you could change the interval of the script to 7 seconds to prevent head parking, it doesn't sound very good.
It would be a good idea to use wdidle3.exe
to disable the IntelliPark feature or adjust the timeout.
If you don't want to do any of that, it would be a great idea to buy a different hard drive, and use the Western Digital Green hard drive as a backup drive that you only need to turn on occasionally. Everyone loves backups.
@Jasper YOu put the swap file on an external USB drive? Lol. – namezero – 2018-10-18T18:00:56.050
@namezero Eh... no, an internal drive. – Jasper – 2018-10-19T22:18:26.663
@Jasper ok sry I thought it was like in the original question an external drive! – namezero – 2018-10-20T08:37:23.760
@namezero It's not actually an external drive in the original question either. The question is about someone taking apart an external drive and then trying to use the hdd inside as an internal drive. – Jasper – 2018-10-22T12:26:36.540
@Jasper Yes indeed, reading clearly helps here! – namezero – 2018-10-22T17:42:25.687
3I can confirm its the green Western Digital, nothing to prevent this? – JL. – 2011-01-23T17:51:54.100
3Unfortunately not. – None – 2011-01-23T17:58:55.497
4@JL. You can of course make sure the drive doesn't get to idle. I put the swap file on my HDD to prevent all the extra writing to my SSD, but also to make sure the HDD wouldn't spin down. – Jasper – 2013-01-22T22:16:06.780
3
SATA drives can spin down either byt request from the host (your windows installation) or by idle timeout (on their own). You can configure the last. E.g. use
– Hennes – 2013-11-08T23:11:22.523hdparm -s Number /dev/sdaX
where number is usually in multiples of 5 seconds. See man hdparm or its windows equivalent.