Windows 8.1 Tip to disable and re-enable hibernate

Many used like me need hibernate but I’ve found that it wasn’t enabled by default.

After goggling I’ve found a command line command that does the enable and disable of hibernate.

First open the command line with administrative privileges then execute the following command:

To turn off hibernate type in the command line powercfg.exe /hibernate off
To turn on hibernate type in the command line powercfg.exe /hibernate on

Drop all tables, stored procedures, views, functions

Recently I had a need to drop all tables, stored procedures, views, functions in a Sql Server database.

In Stackoverflow I’ve found the solution :)

And here it is:

/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 ORDER BY [name])

WHILE @name is not null
BEGIN
    SELECT @SQL = 'DROP PROCEDURE [dbo].[' + RTRIM(@name) +']'
    EXEC (@SQL)
    PRINT 'Dropped Procedure: ' + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'P' AND category = 0 AND [name] > @name ORDER BY [name])
END
GO

/* Drop all views */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = 'DROP VIEW [dbo].[' + RTRIM(@name) +']'
    EXEC (@SQL)
    PRINT 'Dropped View: ' + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'V' AND category = 0 AND [name] > @name ORDER BY [name])
END
GO

/* Drop all functions */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']'
    EXEC (@SQL)
    PRINT 'Dropped Function: ' + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND category = 0 AND [name] > @name ORDER BY [name])
END
GO

/* Drop all Foreign Key constraints */
DECLARE @name VARCHAR(128)
DECLARE @constraint VARCHAR(254)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)

WHILE @name is not null
BEGIN
    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    WHILE @constraint IS NOT NULL
    BEGIN
        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT [' + RTRIM(@constraint) +']'
        EXEC (@SQL)
        PRINT 'Dropped FK Constraint: ' + @constraint + ' on ' + @name
        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' AND CONSTRAINT_NAME <> @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    END
SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'FOREIGN KEY' ORDER BY TABLE_NAME)
END
GO

/* Drop all Primary Key constraints */
DECLARE @name VARCHAR(128)
DECLARE @constraint VARCHAR(254)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)

WHILE @name IS NOT NULL
BEGIN
    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    WHILE @constraint is not null
    BEGIN
        SELECT @SQL = 'ALTER TABLE [dbo].[' + RTRIM(@name) +'] DROP CONSTRAINT [' + RTRIM(@constraint)+']'
        EXEC (@SQL)
        PRINT 'Dropped PK Constraint: ' + @constraint + ' on ' + @name
        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' AND CONSTRAINT_NAME <> @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    END
SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = 'PRIMARY KEY' ORDER BY TABLE_NAME)
END
GO

/* Drop all tables */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = 'DROP TABLE [dbo].[' + RTRIM(@name) +']'
    EXEC (@SQL)
    PRINT 'Dropped Table: ' + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = 'U' AND category = 0 AND [name] > @name ORDER BY [name])
END
GO

Download entire web site for offline viewing

Recently I was goggling for an app (for free) that allows the download of a web site for offline reading and then I came across a StackOverflow post that says use Wget.

I use Wget to download files but I never thought it could be used to download web sites.

Before start using Wget you will need to download Wget. I recommend always the latest version and you can get it for Windows from here.

Now to download a web site you will need to combine several arguments and the result would be:

wget --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains mydomain.com --no-parent http://www.mydomain.com/site

If you want to know the definition of each arguments just type wget –help or check the wget manual page.

Install a clean Windows 8.1 install with a Windows 8 key

As you might already know you can update your windows 8 to windows 8.1 without the need of a new product key but you can’t install a clean windows 8.1 using windows 8 product key.

Well this is not entirely true and I will teach you how to do that.

The first thing you need to do is Create a Windows 8.1 Bootable USB device.

Next you will need to locate the folder sources inside your USB device with windows 8.1 installation. :\sources

Then create a new text document with the name ei.cfg

Enter the following content in ei.cfg:

[EditionID]
Professional
[Channel]
Retail
[VL]
0

Now boot your computer and start the windows 8.1 installation.
During the installation you will need to insert a product key. Use the your windows 8 product key.

Wait the installation to finish and you will have a clean windows 8.1 installation with a windows 8 product key.

Create a Windows 8.1 bootable USB device

In these days it’s very common that computers/laptops don’t have a optical drive. Because of this it’s no surprise that when you need to install Windows 8.1 you will need a USB device, such as a flash drive.
This was my case, I recently needed to installed Windows 8.1 and I didn’t have a optical drive. So I needed to find a way. In the next ¬†steps I will teach you how to do that.

The first thing you need is a USB device, such as a flash drive.
The last thing you need is how to create a windows 8.1 bootable USB device.

The last part it’s easy thanks to the Windows Installation Media Creation Tool. This is the only tool you will need.

When you run the Windows Installation Media Creation Tool for the first time you will be presented with the following screen:

Windows-Installation-Media-Creation-Tool-1

In this screen you need to choose the language, the windows 8.1 edition and the architecture. Then click in the Next button.
In the next screen you need to choose that you want to save the installation file to the USB flash drive. Then click in the Next button.
If you want you can save it to an ISO and then burn the ISO to a optical drive such as a DVD.

Windows-Installation-Media-Creation-Tool-2

In the next screen you choose the USB flash drive. Then click in the Next button.

Windows-Installation-Media-Creation-Tool-3

In the last screen you need to wait the download and the creation of windows 8.1 bootable USB device.

Windows-Installation-Media-Creation-Tool-4

After this last step you will be ready to install windows 8.1.