Posts Tagged ‘task’

Windows 7 comes with the Aero skin by default which might look nice but consumes a great deal of resources – and with them, power. I have experienced a loss of up to two hours of battery life on my notebook when turning Aero on which one can get back by switching to the classic skin – that ugly gray one, that was used in the times before Windows XP.

It would be great if Windows provided an option to set a scheduled task to trigger on plugging or unplugging the power supply or to configure the power settings to change themes automatically but unfortunately we don’t have that luxury, so we have to do it ourselves, in a slightly less elegant way.

What you need is a small VBScript which you can find here and a PowerShell script which checks in what state the notebook battery is in. To create that script, open a new notepad and paste the following into it:

$sav = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
while ($true)
{
start-sleep -s 5
if (((Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus -eq (1 -or 3 -or 4 -or 5 -or 10 -or 11)) -and ((Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus -ne $sav))
{
& ‘C:\Windows\Resources\Ease of Access Themes\Classic.theme
$sav = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
}
else
{
if ((Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus -ne $sav)
{
& ‘C:\Windows\Resources\Themes\Aero.theme
$sav = (Get-WmiObject -Class Win32_Battery -ea 0).BatteryStatus
}}}

Adjust the paths printed bold to the location of the themes you want to use if you want different ones (the first one is the one that is applied on unplugging the supply, second is for replugging). Save the script as a .ps1 file. If you haven’t yet created the VBScript, do it now following the above link. Remember to adjust the path to the ps1 script used there to yours. If you now launch the VBScript the PowerShell script should be started silently. If you get an error or the script won’t start, you first have to configure your system to allow executing PowerShell scripts – see the instructions below the code provided here.

The locations of the themes are
C:\Windows\Resources\Ease of Access Themes for the classic styled themes.
C:\Windows\Resources\Themes for preconfigured Aero style themes and
C:\Users\[YourUsername]\AppData\Local\Microsoft\Windows\Themes for custom themes (the AppData folder is hidden by default).

To automate everything you can set the execution of your VBScript as a scheduled task. Do so by entering Task Scheduler into your Start-menu search bar. Set up the task for execution on start up if you want it to be run on every session.

Windows 8 Task Manager Improvements (Consumer Preview)

Thursday, March 1, 2012 posted by CSch

Along with all the other changes that Windows 8 introduces to the operating systems’ family, the ones made to the Task Manager will likely be welcomed by most users. Along with a revamped interface it brings along an enhanced pool of functionalities.

Opening the Task Manager is still done in the old way: you can either right-click the taskbar on the classic desktop and choose the appropriate action or press Ctrl + Alt + Del. As before, it is also available from the applciation menu which however is now part of the Metro menu.

Upon opening you will only be presented with a small window offering you to handle running application, which might be a good way to bringing the manager closer to unexperienced users. By clicking on More details, you will get to the new detailed Task Manager view, having all the options you had in earlier versions, plus, a few new ones.

You will notice a few more tabs in the new manager – the Details, Users and Services tabs are basically what you will be used to from previous versions. The performance tab has visually been enhanced and now features Disk and Network usage. The Startup tab gives you the option to edit the applications that are run on system startup just like msconfig did – this function has now moved to Task Manager. App history gives you an overview of your App usage (CPU, Network, Tile Updates). The Processes tab however is the big deal.

It lists all the running processes, divided into categories (Apps, Background processes, Windows processes) and furthermore shows all their resource usage. Heavy resource users are displayed on a dark yellow to orange background – the color gets lighter the less resources the process uses.
Notice that the Apps you do not use at the moment do not drain any CPU resources – they are put to “sleep” if running in the background.

The aim of this guide is to create a folder whose content is deleted if the contained files have not been accessed longer than a specific time (this process is applied to single files, not the whole folder). I will choose two weeks for demonstration purposes (= 14 days). Such a folder can be used as temporary folder of any kind, be it for downloaded files/installers or to just keep the desktop clutter-free.
This can be achieved with a combination of PowerShell script and Windows task scheduler. The folder that I will use for this will be C:\Users\howtoforge\Desktop\Temp and is located on my desktop for easy access. To keep order to it, create another folder for your custom scripts if you haven’t already got one, mine will be C:\Scripts.
Open a new instance of notepad and save it in your scripts folder as delete_temp.ps1. .ps1 is the file extension for PowerShell scripts. Now enter following into the script:

cd “C:\Users\howtoforge\Desktop\Temp”;
Get-Childitem | Foreach-Object {if ($_.LastAccessTime -le (get-date).adddays(-14)) {remove-item -recurse -force $_}};

Save the script again. What it does: the script changes into the directory that we want to observe, looks at its items and then deletes every one whose last access time is older than 14 days recursively (it only looks at the items directly placed in the folder, not at subdirectories). The time interval is specified in the adddays attribute of the get-date function here (which can also be addmonths, addhours, etc…) and is a negative number to actually subtract the number of days from the present date. You can change it to your likings.
The script being ready, you have to configure PowerShell to enable calling scripts – therefore open an elevated command line (search the menu for cmd, right-click and select Run as administrator). Open PowerShell by entering

powershell

Afterwards, enter

Set-ExecutionPolicy RemoteSigned

to enable calling scripts. Now you can test your script by right-clicking it and selecting Run with PowerShell. If nothing goes wrong (no red text in the flashing window), proceed to schedule the task, otherwise check your script for errors.

To schedule the task, open Control Panel > System and Security > Administrative Tools > Schedule Tasks. On the left pane, select Task Scheduler Library, then right-click the central task-list and select Create New Task.
On the General tab, give the task a name and a description. Furthermore, choose your version of Windows and optionally choose to run it with highest privileges.
The Trigger tab defines what will call the script – hit New and choose one or more of the various possibilities and events. I choose to run the script when the machine goes idle, since the script will blink up in a PowerShell window when called, and I don’t want that to disturb my work (although it’s really only a split second if you don’t delete several GB of files).
On the Actions tab you define what to do – hit New again. Now don’t enter the actual script as program to run – this goes to the Add arguments line (enter the full path here). What you need to do is to call the PowerShell executable with the script as an argument. I use PowerShell 1.0 which is located in C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe – enter this path into the Program/script line and hit OK.
Now configure the next two tabs for your needs and hit OK again to create the task.

The selected folder will then be scanned for files that haven’t been accessed for longer than the given period every time the task triggers.

Create System Restore Points in Win XP automatically

Friday, October 7, 2011 posted by CSch

Since older system restore points are deleted after some time, it is always good to create some new regularly. But to always have to browse through the countless menus day by day can be really annoying, that is why we will use Windows’ Notepad and Scheduled Tasks functions to ease our lives.
First we create a short script that creates system restore points in our notepad, therefore open one and type in these two lines:

Set auto_rp = getobject(“winmgmts:\\.\root\default:Systemrestore”)
auto_sys_rp = auto_rp.createrestorepoint (“Automatic System Restore Point”, 0, 100)

When saving, make sure to not save it as text document but select All Files from the Save as type dropdown menu and name it something like automatic_sysrp.vbs. vbs is the type of file here, make sure you have it correct, since otherwise the script will not be executable.
Now that you have created the script, you can doubleclick it to create a system restore point. But to have it done automatically, we are going to use Windows’ Scheduled Tasks function. Therefore, enter Start > Control Panel > Performance and Maintenance > Scheduled Tasks. Select File > New > Scheduled Task from the control bar. Give it a name, rightclick it and select Properties.

In the opened window, browse the location of the vbs script you just created and go to the Schedule tab. Enter a time when the restore point shall be created and click on Apply when you are finished. A new system restore point will now be created at the time you specified or on doubleclick upon the script.