Friday, December 18, 2009

Log on to Windows 7 Automatically

It used to be a pretty complicated task to configure auto-logon in Windows XP.  It takes some tinkling to the Windows Registry data (see here.)  However, Windows 7 has changed that.  Now you can set up a default user to log into Windows automatically through some dialog boxes.  And the password is not stored as plain text in the registry anymore.  Two ways to bring up the User Accounts dialog box:
  • Type "netplwiz" in the Start menu search box (Run window) and hit Enter.
  • Type "control userpassword2" in the Start menu search box (Run window) and hit Enter.
For detail instructions on how to do this, check out this article on www.howtogeek.com.

Unfortunately, you can't access this dialog box through the Control Panel; I think Microsoft intentionally omitted it.  But you can add it back into the Control Panel by modifying the following Registry keys:
[HKEY_CLASSES_ROOT\CLSID\{98641F47-8C25-4936-BEE4-C2CE1298969D}] 
@="Advanced User Accounts" "InfoTip"="Starts the \"Control Userpasswords2\" Admin Screen" "System.ControlPanel.Category"="9" 

[HKEY_CLASSES_ROOT\CLSID\{98641F47-8C25-4936-BEE4-C2CE1298969D}\DefaultIcon] 
@="%SystemRoot%\\System32\\netplwiz.exe" 

[HKEY_CLASSES_ROOT\CLSID\{98641F47-8C25-4936-BEE4-C2CE1298969D}\Shell] 

[HKEY_CLASSES_ROOT\CLSID\{98641F47-8C25-4936-BEE4-C2CE1298969D}\Shell\Open] 

[HKEY_CLASSES_ROOT\CLSID\{98641F47-8C25-4936-BEE4-C2CE1298969D}\Shell\Open\command] 
@="Control Userpasswords2" 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ControlPanel\NameSpace\{98641F47-8C25-4936-BEE4-C2CE1298969D}] 
@="Add Advanced User Accounts to Control Panel" 

Tuesday, December 1, 2009

How to Remove GPT Protective Partition from a Drive in Windows

Warning: This procedure will erase all data on the disk. Please backup your data before proceed.

In Windows, you can use a program called DISKPART, which is a command line program, to remove a GPT Protective Partition from a disk. Here's how:
  1. Bring up your Command Prompt program
  2. Type DISKPART at the prompt
  3. Then type list disk in DISKPART's prompt to show all disks on the machine.
  4. Type select to set the specific partition: select disk 1
  5. Then type clean will remove the GPT Partition from the selected disk
Now, you can go to Disk Management Console and start formatting the 'unallocated' partition on this drive. Have fun!

Thursday, October 29, 2009

How drop multiple tables in MySQL

To create DROP statements for all table begins with 'prefix_' from database 'my_database':
> SELECT CONCAT('DROP TABLE',table_name,';') FROM information_schema.TABLES 
    WHERE table_schema = 'my_database' AND table_name LIKE 'prefix_%';
Or better yet, create a one-liner:
> SELECT CONCAT('DROP TABLE',GROUP_CONCAT(table_name),';') FROM information_schema.TABLES 
    WHERE table_schema = 'my_database' AND table_name LIKE 'prefix_%';

Example of creating store procedure:
mysql> delimiter $$
mysql> create procedure drop_tables_like(pattern varchar(255), db varchar(255))
    -> begin
    -> select @str_sql:=concat('drop table', group_concat(table_name))
    -> from information_schema.tables where table_schema=db and table_name like pattern;
    -> prepare stmt from @str_sql;
    -> execute stmt;
    -> drop prepare stmt;
    -> end$$
mysql> call drop_tables_like('prefix_','my_database')$$
mysql> drop procedure if exists drop_tables_like$$
mysql> delimiter;