Posts Tagged ‘delete’

Take Ownership of a File or Folder by Command in Windows

Wednesday, April 3, 2013 posted by CSch

Taking ownership of files in Windows is necessary to edit or delete system or program files that you have no access to by default. There are multiple ways to achieve that goal, like doing everything manually through the Properties menu, applying a registry tweak or, as described here, executing a command in the Command Prompt. Note that taking ownership will not let you edit every system file. Windows has set precautions so that you don't edit any of the most important files which may be helpful in some cases but can be really, really annoying in other.

To start off, you need an elevated command prompt which is simply a command prompt opened as administrator. In Windows 8 you can open that by right-clicking the bottom left corner of the screen and selecting Command Prompt (Admin). In Windows 7 and previous, search the main menu for cmd, right-click it and select Open as administrator.

You need two commands now: one to actually take ownership of the file or folder and one to grant yourself access rights. These are the two commands you will want to use:

For folders, use:

takeown /f folder_name /r /d y
icacls folder_name /grant username_or_usergroup:F /t /q

For files, use:

takeown /f file_name /d y
icacls file_name /grant username_or_usergroup:F /q

The commands basically only differ in a few switches that make the folder procession run recursively. If you want to edit only one folder instead of the whole recursive lot, remove the /r and /t switches from the commands. For more info on the commands, simply enter takeown /? or icacls /? into the command prompt.

If I wanted to take control of my Program Files folder, I'd need to enter the following:

takeown /f "C:\Program Files" /r /d y
icacls "C:\Program Files" /grant christian:F /t /q

Delete Windows.old Folders from Previous Windows Installations

Wednesday, March 27, 2013 posted by CSch

Windows takes a nice precaution for us when it comes to installing a clean Windows system on a hard drive or partition that already has a version of Windows installed: If you forgot to backup files from your old installation but already have the fresh one installed you still have a way of getting what you want:
When installing Windows onto an already existing Windows, most of the old files are stuffed into a folder called windows.old which is placed on your newly formated C:\ drive. That folder contains the most important data from your previous installation, which is the Users folder as well as the Windows and Program Files folders. This way, you have an automatic backup of your files that you can get back to if you forget to backup yourself.

Now there is one downside to this procedure: the folders that are backed up tend to get very large. They can take up several gigabyte of data, depending on how large your folders were. So if you don't actually need that backup, why keep it?
All of you who have ever tried to delete Windows system files will already see where this is going: part of the windows.old folders are old system files and Windows still recognizes them as those. But Windows actually has a neat little trick to delete them anyway!

Open up the Control Panel and head to the System and Security section. Now click on Free up disk space under Administrative Tools:

fff1

A window comes up that is usually used to cleanup temporary files and stuff. But we need to clean up system files, so click on the appropriate button in the Description panel:

fff2

A similar window will upon but this time we'll have different cleanup options. Previous Windows installation(s) is the one that we want to remove:

fff3

As you see it is 25 GB large on my machine which is a lot of space for files i don't need anymore. That's why, after we have double-checked if we really, really don't need them, we check the box next to it and click on the OK button. Confirm by clicking Delete Files on the next window and you are good to go with a whole lot of free space.

Bring back delete confirmation dialog in Windows 8

Wednesday, January 2, 2013 posted by CSch

When moving an item to the recycle bin in older versions of Windows you were asked to confirm that step - this dialog was removed in Windows 8 but can be brought back with a simple tweak:

Right-click the Recycle Bin and select Properties. Afterwards check the Display delete confirmation dialog checkbox. You should now be asked to confirm on delete again:

recbin

The majority of graphical environments let you choose to remember the passwords you enter somewhere to ease access to something but they usually don't tell you how to delete them again. Most Linux desktop distributions have a tool installed where all your saved passwords for network drives are stored in that is called Passwords and Keys.

You can find the saved passwords right on the first Passwords tab. Right-click the one you want to remove and select Delete. Confirm your choice by clicking Delete again on the window that pops up.

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.

Properly Uninstall Software on Windows with Revo Uninstaller

Tuesday, January 3, 2012 posted by CSch

The built-in Windows tool to add and remove software is commonly used to install and uninstall software, in most cases an own uninstaller comes with the program. However, this uninstaller usually does its job quite sloppy, since numerous files, folders and/or registry entries are left behind after installation. This can either be wanted, if the left files serve as configuration preservers for the case of reinstallation of the program or, as it is in most cases, is just taken lightly by the programmers, meaning that the left files are actually only data junk never to be used again.
This data junk, if stored in masses, can slow down your computer over time. While the best method to get rid of it is to format your hard drive and reinstall the operating system from time to time, you may have reasons to not do that, but to look for a more immediate way to get rid of or to prevent such installation leftovers.
One way to uninstall software more effectively as with their own uninstaller is doing so with Revo Uninstaller.

This piece of software provides multiple steps of uninstalling - it first removes the programs with their own uninstaller and then scans the system for the so-called software rot.

If any leftover files are found, they are shown and you are given the option to delete them seperately. Only delete the files that you are sure you won't need anymore - deleting files you don't know or recognize can cause severe problems.

Furthermore, Revo Uninstaller comes with a bunch of useful features as emptying browser caches, deleting temporary files, Windows search queries, several histories and erasing all tracks of deleted files.

Permanently Delete Files (Windows)

Thursday, December 8, 2011 posted by CSch

To permanently delete files instead of just throwing them into the waste-bin with Del, select them and press Shift and Del simultaneously. Confirm the appearing dialogue and you'll have made sure that your trash does not overflow with forgotten data:

Remove Erroneous Firefox Configuration Entry (Windows 7)

Tuesday, December 6, 2011 posted by CSch

If you entered an erroneous entry into the about:config database of Mozilla Firefox, you will have noticed that there is no option in the browser itself that enables you to remove that entry. Instead, find the config file in your desktop explorer:

C:\Users\YourUsername\AppData\Roaming\Mozilla\Firefox\Profiles\weirdstring\prefs

YourUsername has to be replaced with the name of the user you're logged in with and weirdstring is a string consisting to mainly numbers which represents your Firefox profile. Edit the prefs file with notepad, track down the entry you want to delete and erase the full line.

Clear Firefox Browser Cache

Tuesday, November 22, 2011 posted by CSch

Browser Cache (or Internet Cache) is there to speed up your browser performance by saving sites and items you visited on the internet on your hard disk and recalling them when you visit them again. However there may be times when you want to delete that cache because it either consumes too much disk space (its size can easily climb to 500MB and more) or you do not want someone who has access on your computer to see what sites you visited. In Firefox there is a simple solution for this. Click on the main button and open the Options window:

Select Advanced and go to the Network tab.

The Offline Storage section shows you how large your cache is at the moment. Here you can use the Clear Now button to delete your cache.

If you stayed loyal to Firefox 3.6, go to Edit > Preferences instead.

Unlock and Delete Any File (Windows)

Friday, October 14, 2011 posted by CSch

Sometimes it is necessary to just put a file that does not want as you want in the trash can. And sometimes doing this simple thing is not possible, because the file is being used by another program or is bound to other processes . If this is the case, the file is treated as if it was "locked" and changes cannot be done to it. If you are sure that the file needs to be deleted anyway, there is a tool called Unlocker that is able to cut off any file from its bonds so that it can be moved, renamed or even deleted. This can be pretty handy if your computer too stubborn to see its mistakes.

Unlocker is available for both 32 bit and 64 bit systems on the emptyloop homepage: http://www.emptyloop.com/unlocker/#download

To be able to use Unlocker with a rightclick, make sure that the Explorer extension is checked during the installation process.
To delete files afterwards, rightclick them and select Unlocker. The opening window will tell you if the selected file is locked or not and gives you the option to move, rename or delete it instantly.