Posts Tagged ‘files’

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

Hide files in Linux Mint/Ubuntu

Friday, May 25, 2012 posted by CSch

Hiding specific files in Ubuntu and Mint is done by placing a dot (.) in front of their name, e.g. renaming the file muh to .muh will mark it as hidden and render it invisible the next time you open its directory (this does not work on the desktop).

To make files hidden without altering their name, create a new document called .hidden in the folder where the files that you want to hide are located. Enter the names of the files into the document, one name per line, then save it. Open the target folder to check if it worked.

To make hidden files visible, simply hit Ctrl + H.

Hide folders by making them system folders on Windows

Thursday, April 26, 2012 posted by CSch

One of the basic things one does while configuring a Windows system is to enable viewing hidden files. So basically it is impossible to hide files by making them "hidden".

What helps against most nosy people though is to make a file a system file or folder - that way the tagged file will remain hidden even if "hidden" files are made visible (of course one can still make system files visible but few people will enable that since it's usually not necessary).

To tag a file a system file, open a command prompt by entering cmd into your search bar. Enter following into the command line, replacing the path I use with the one to your file (+s is for systemfile and +h is for hidden):

attrib +s +h C:\Users\howtoforge\Desktop\bla

To make it visible again, just turn the plusses into minusses:

attrib -s -h C:\Users\howtoforge\Desktop\bla

Hide files by merging them with Winrar on Windows

Tuesday, March 27, 2012 posted by CSch

Apart from alternate data streams, there is another, perhaps easier way to hide files within others. All you need for it is WinRar (download the 32 or 64 bit version, depending on what operating system you use). To simplify things, I also like to install WinRar's context menu items.

First off, you need the files you want to merge - I will slip a folder into a picture file. Right click the item you want to hide and select Add to "secret.rar" from WinRar's context menu:

Afterwards open a command line by searching the Windows menu for cmd or entering the same into a Run prompt, which you get by hitting Windows key + R. In the command line interface, change directoy to the location of the two files you want to merge (I have them on my desktop here):

cd C:\Users\howtoforge\Desktop

Afterwards, copy the files together with the /b switch by seperating them with plus characters and choosing a third destination file - choose another picture file (which will be created by the command) if you want to hide your stuff in a picture (use the exact syntax):

copy /b Koala.jpg + secret.rar NewPicture.jpg

The new file will appear in the folder you directed the command line to, the desktop in my example. To view the hidden content, open up WinRar and go to File > Open archive. From the drop-down menu where it says All archives, choose All files instead and browse the picture you just created. Double click it and you should be able to see the stuff you placed in there!

The only thing to complain about is that this method increases the output object's displayed size.

Undelete Deleted Files with Recuva on Windows 7

Thursday, February 9, 2012 posted by CSch

Apart from CCleaner, Piriform has released some other useful pieces of software. Among them is Recuva, a tool to save and undelete removed data.

Files you delete are not physically removed from your hard drive until they are overwritten by new data, which makes it possible to retrieve them as long as nothing new is written on their clusters - this also includes removing data or wiping hard drives with special software such as CCleaner since they take care of deleting data properly by overwriting their hard disk space (this method is used to make deleted data inaccesible).

After checking for deleted files, make sure to go through the list for your wanted files carefully since their filenames may have changed like in the screenshot above.

You can download Recuva here: http://www.piriform.com/recuva
Like for CCleaner, there is also a portable version: http://www.piriform.com/recuva/features/portable-version

Windows Powershell Script to Sort Music From Folder to Library

Thursday, February 2, 2012 posted by CSch

The aim of the following script was to take music from a single folder with unsorted but tagged audio files and sort them into the music library according to artist and album. It often happens that you have audio files in your browser's download folder or your instant messenger's received files folder where they usually don't belong. The script should be able to move them into your music library and put them into correct folders named after the artist and the album they're on.

 

$controlssource = 1
$controlsdest = 1

$objshell = New-Object -ComObject Shell.Application
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objform = New-Object System.Windows.Forms.Form
$objform.Text = "Move Audio Data"
$objform.Size = New-Object System.Drawing.Size(300,260)
$objform.StartPosition = "CenterScreen"

$objform.KeyPreview = $True
$objform.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objform.Close()}})

$movebutton = New-Object System.Windows.Forms.Button
$movebutton.Location = New-Object System.Drawing.Size(20,170)
$movebutton.Size = New-Object System.Drawing.Size(75,23)
$movebutton.Text = "Move"
$movebutton.Add_Click({$x="move";$objform.Close()})
$objform.Controls.Add($movebutton)

$copybutton = New-Object System.Windows.Forms.Button
$copybutton.Location = New-Object System.Drawing.Size(100,170)
$copybutton.Size = New-Object System.Drawing.Size(75,23)
$copybutton.Text = "Copy"
$copybutton.Add_Click({$x="copy";$objform.Close()})
$objform.Controls.Add($copybutton)

$cancelbutton = New-Object System.Windows.Forms.Button
$cancelbutton.Location = New-Object System.Drawing.Size(180,170)
$cancelbutton.Size = New-Object System.Drawing.Size(75,23)
$cancelbutton.Text = "Cancel"
$cancelbutton.Add_Click({$a=0;$x="nil";$objform.Close()})
$objform.Controls.Add($cancelbutton)

$objlabel = New-Object System.Windows.Forms.Label
$objlabel.Location = New-Object System.Drawing.Size(10,110)
$objlabel.Size = New-Object System.Drawing.Size(280,40)
$objlabel.Text = "Please specify whether you want to copy or to move your files. Moving the files will remove them from their original directory."
$objform.Controls.Add($objlabel)

if ($controlssource -eq 1){
$objlabel2 = New-Object System.Windows.Forms.Label
$objlabel2.Location = New-Object System.Drawing.Size(10,10)
$objlabel2.Size = New-Object System.Drawing.Size(280,15)
$objlabel2.Text = "Path to file origin:"
$objform.Controls.Add($objlabel2)}

if ($controlssource -eq 1){
$objtextbox = New-Object System.Windows.Forms.TextBox
$objtextbox.Location = New-Object System.Drawing.Size(10,25)
$objtextbox.Size = New-Object System.Drawing.Size(230,20)
$objform.Controls.Add($objtextbox)}

if ($controlsdest -eq 1){
$objlabel3 = New-Object System.Windows.Forms.Label
$objlabel3.Location = New-Object System.Drawing.Size(10,50)
$objlabel3.Size = New-Object System.Drawing.Size(280,15)
$objlabel3.Text = "Path to music library:"
$objform.Controls.Add($objlabel3)}

if ($controlsdest -eq 1){
$objtextbox2 = New-Object System.Windows.Forms.TextBox
$objtextbox2.Location = New-Object System.Drawing.Size(10,65)
$objtextbox2.Size = New-Object System.Drawing.Size(230,20)
$objform.Controls.Add($objtextbox2)}

if ($controlssource -eq 1){
$browsebutton1 = New-Object System.Windows.Forms.Button
$browsebutton1.Location = New-Object System.Drawing.Size(250,24)
$browsebutton1.Size = New-Object System.Drawing.Size(26,22)
$browsebutton1.Text = "..."
$browsebutton1.Add_Click({$fold1 = $objshell.BrowseForFolder(0, "Select Folder", 0, "");$objtextbox.Text = $fold1.self.path})
$objform.Controls.Add($browsebutton1)}

if ($controlsdest -eq 1){
$browsebutton2 = New-Object System.Windows.Forms.Button
$browsebutton2.Location = New-Object System.Drawing.Size(250,64)
$browsebutton2.Size = New-Object System.Drawing.Size(26,22)
$browsebutton2.Text = "..."
$browsebutton2.Add_Click({$fold2 = $objshell.BrowseForFolder(0, "Select Folder", 0, "");$objtextbox2.Text = $fold2.self.path})
$objform.Controls.Add($browsebutton2)}

$objform.Controls.Add($copybutton)

#$objform.topmost = $True

$objform.Add_Shown({$objform.Activate()})
[void] $objform.ShowDialog()

$sFolder = $objtextbox.Text
$mFolder = $objtextbox2.Text
#$sFolder = "C:\Users\Public\Music\Sample Music"
#$mFolder = "C:\Users\howtoforge\Music"
$objfolder = $objshell.namespace($sFolder)

if ($X -eq "nil") {exit}

foreach ($strfilename in $objfolder.items())
{
for ($a ; $a -le 266; $a++)
{
if ($objfolder.getDetailsOf($objfolder.items, $a) -eq "Contributing artists")
#if ($objfolder.getDetailsOf($objfolder.items, $a) -eq "Albuminterpret")
{
$artist = $objfolder.getDetailsOf($strfilename, $a)
}
if($objfolder.getDetailsOf($objfolder.items, $a) -eq "Album")
{
$album = $objfolder.getDetailsOf($strfilename, $a)
}
}
if ($artist -and $album)
{
if (!(test-path($mFolder + "\" + $artist + "\" + $album + $strfilename)))
{
new-item($mFolder + "\" + $artist + "\" + $album) -itemtype directory
if($x -eq "copy")
{
copy-item $strfilename.Path ($mFolder + "\" + $artist + "\" + $album)
}
if($x -eq "move")
{
move-item $strfilename.Path ($mFolder + "\" + $artist + "\" + $album)
}
}
}
clear-variable artist
clear-variable album
$a=0
}

The script runs for every audio file in the specified folder that possesses both given details, here they are Contributing artists and Album (you can change it to look for different details but this does not always make sense since the script later creates the folders in the library depending on those data - there are different artist details however which can be chosen from, since not every audio file has all of them (album artist, contributing artists...). To change them, just change the single instance of them in the script. Adjust their names to the display language of your system!).

If the files have both details specified, the script goes to your library and, if not already present, creates a folder with the artist's title, a folder with the album title inside of that, and copies or moves the file to that location.

If you have fixed folders that you don't want to browse anew everytime you run the script, comment out the top two lines and the two bold lines, uncomment the two lines underneath the latter. Change the path given there to the path of your folders. You can also just uncomment one of them, just make sure to comment out the right lines when you uncomment one.

To run the script, copy and paste it into a notepad and save it as .ps1 file (select All Files from the type dropdown menu). Then right-click the file and run it with windows powershell. If it is not working, you might have to change your execution policy if you have not already done so. To accomplish that, search for powershell in the Windows menu search bar and right-click to run it as administrator. Enter

set-executionpolicy remotesigned

and run the script again. The script works finde on my Windows 7 Enterprise 64bit machine with PowerShell 1.0 installed, if some one has improvements to make I'd be glad to read.

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:

There is a feature in NTFS data system that lets you easily hide your files from nosy people using your computer which is called Alternate Data Streams. What they basically do is to hide files behind others, using them as a "container", but they only are executable if you enter a specific syntax in your command line. I will show you in a few examples.
I have the text document mysecrets.txt which I want to hide inside the legal.txt document. They are both placed directly on my C:\ drive to simplify things. To achieve that, I open a command line and type in:

type C:\mysecrets.txt >C:\legal.txt:mysecrets.txt

With the type command, you can stuff any file into an alternate data stream. Next you give the file to hide, followed by a greater-than sign, followed by the the path where you want to hide the file - here, give the file you want to stuff things in, a colon, and the hidden file's name (this can basically be any, you call the hidden file by this given name then). The colon is the trademark of an alternate data stream, every file separated from another file with a colon will become the first file's alternate data stream.

Text files are not the only files you can hide away with alternate data streams, basically you can do it with any file, even executables. However you cannot open every file from an alternate data stream - starting executables for example has been disabled for security's sake because, as you might have noticed, AltDS can be used to build pretty evil malware. To open a hidden file, you just pick the program to do so and open it the usual way through the command line, for example like this:

notepad C:\legal.txt:mysecrets.txt

You can also do this for videos, music, whatever, just pick the appropriate application. For executables however, this is no longer possible. However there are some slightly more complicated workarounds to do this. You can either have a symlink of the hidden file made, which is then executable and deletable afterwards, or write commands into the hidden file which can be executed by the shell, creating another executable or whatever you want to do with it.
Be aware however that alternate data streams will be lost after moving their containers to another server! It is not possible to mail multi-streamed files, even if the receiving file system is NTFS formatted.
To uncover alternate data streams on Windows Vista or later, direct your command line tool to the folder you want to check and enter

dir /r C:\path\to\your\folder

You cannot hide whole folders in alternate data streams, except if they are compressed.
The easiest way to delete alternate data streams is to copy the whole file onto another data system via explorer, ftp or mail. However there is also software to detect and deal with them.

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.

Encrypt Files With Axcrypt on Windows

Monday, October 10, 2011 posted by CSch

AxCrypt is a software giving you the possibility to encrypt files with a password and a keyfile which you both need to decrypt it again. You can either encrypt the file itself or a copy of it, in case you choose the latter the encryption output can be an executable file which does not need the AxCrypt software to be decrypted (but still the password and/or the keyfile).

You may ask what kind of file the keyfile is - in case you let AxCrypt itself produce a keyfile, it is a simple text document with a short code in it. You can however choose any file you want as your keyfile (I have tested it with a .vbs script and a .wav file, both work) which offers a great deal of security especially against non-professional attackers.

Upon decrypting you need all info you used when encrypting a file - the password as well as the keyfile, depending on which of them you used. If you send encrypted files to other people, the receiver will need AxCrypt installed if you have encrypted your files without choosing the option to produce an executable file. If you did however, the receiver will only need the keys to open the file, but no additional software installed.

Download AxCrypt on http://www.axantum.com/axcrypt/