Showing posts with label delete. Show all posts
Showing posts with label delete. Show all posts

Sunday, September 12, 2010

EXIF Eraser – Free EXIF/IPTC/XMP erasing software

A long time ago, I was using Delphi to write all of my software. I think Delphi was and still is the best choice for rapidly developing Windows UI applications (though I have to admit, I have superficial familiarity with Visual Basic and C#, that I believe are also good candidates for Windows UI development). The biggest problem with Delphi, is that you have to write in Pascal, which is kind of an anachronistic language.

Anyway, a month ago, I decided It will be a nice thing, to have a look at Delphi again, and check what way it did along the years I left it. I downloaded the latest Delphi version from http://www.embarcadero.com/, which I believe is currently the company that maintains and develops the future of Delphi. Back then, Delphi was strongly identified with Borland. I was surprised to find, that things didn’t changed much along the years. Many features of modern IDEs were added, but the main idea was pretty much identical.

In order to refresh my Delphi development skills, I decided to write a small utility program, that wipes EXIF, IPTC and XMP meta data from image files. EXIF (Exchangeable Image File) data is a record of what camera settings were used to take a photograph. This data is recorded into the actual image file. Therefore each photograph has its own unique data. EXIF data stores information like camera model, exposure, aperture, ISO, what camera mode was used and whether or not a flash fired. IPTC and XMP are also additional meta data that are attached to image files.

I named the utility: Free EXIF Eraser. The nice thing is, that it deletes EXIF, IPTC and XMP meta data without doing any modifications to the original image. That means, the quality of the original image is kept untouched.

It was so fun and easy to get back to Delphi development, that I decided to put a bit more effort on my small utility: I dedicated for it a special domain and created a home page. If you need a small and lightweight utility, that will easily erase EXIF, IPTC and XMP meta data, you can check: http://www.exiferaser.com

Tuesday, April 20, 2010

Unable to delete files in Windows Vista/Windows 7

If you have reinstalled windows machine, without entirely erasing your disk you have probably encountered a problem in which you are unable to delete files or directories. These files belonged to the older windows machine (the previous user(s) of that machine), and therefore, your new operating system will allow you to access these files, but not delete them.

In order to delete these files, we first have to take control over them. This can be done by using 2 command line utilities. First open a command line as Administrator. This can be pressing the “Start” button and writing “cmd” on the search edit box. When the “cmd.exe” file is shown, right click on it and choose: “Run as administrator”. Another way of doing it, is writing “cmd” on the search box, and then pressing “Ctrl + Shift + Enter” instead of Enter.

After the the command line is open as administrator, we first run this command on the file we would like to delete:
takeown /f "file_name" /d y

For example:
takeown /f "c:\some dir\some undeletable file" /d y

If we would like to delete a directory instead of a file, we can use this command, which runs recursively on all the sub directories:
takeown /f "directory_name" /r /d y

For example:
takeown /f "c:\some undeletable directory" /r /d y

After running this command we should run this command on a single file:
icacls "file_name" /grant administrators:F

For example:
icacls "c:\some dir\some undeletable file" /grant administrators:F

And for a directory and it’s sub directories:
icacls "c:\some undeletable directory" /grant administrators:F /t

After running these 2 commands, simply delete the file or directory using the Windows explorer.

Saturday, July 11, 2009

Programmatically Delete a database in SQL server

Sometimes we would like to programmatically delete SQL server database. Simply writing:
DROP DATABASE 'database_name'
is not always a good solution, for 2 main reasons:
  1. The database may be already deleted, therefore we will get exception telling there is no such database to delete.
  2. There may still be existing connections to the database, preventing from the database being deleted.
The first problem can be easily solved by checking the existence of the database before deleting it:
IF EXISTS (SELECT 1 FROM SYS.DATABASES WHERE NAME = 'database_name') BEGIN
DROP DATABASE 'database_name'
END
GO
Solving the second problem is a bit harder. In order to delete the database, all existing connections needed to be closed. This should be done carefully since we do not want to close our own connection. This script, first closes all existing connections and then drops the database:
DECLARE @spid INT,
@cnt INT,
@sql VARCHAR(255)
IF EXISTS (SELECT 1 FROM SYS.DATABASES WHERE NAME = 'database_name') BEGIN
SELECT @spid = MIN(spid), @cnt = COUNT(*)
FROM master..sysprocesses
WHERE dbid = DB_ID('database_name')
AND spid != @@SPID
PRINT 'Starting to KILL '+RTRIM(@cnt)+' processes.'
WHILE @spid IS NOT NULL
BEGIN
PRINT 'About to KILL '+RTRIM(@spid)
SET @sql = 'KILL '+RTRIM(@spid)
EXEC(@sql)
SELECT @spid = MIN(spid), @cnt = COUNT(*)
FROM master..sysprocesses
WHERE dbid = DB_ID('database_name')
AND spid != @@SPID
PRINT RTRIM(@cnt)+' processes remain.'
END
DROP DATABASE 'database_name'
END
GO
Note that the name of the database (“database_name” in this example) can be replaced with SQL parameter.