/*
 * Automatically log a set user in, on reboot, in Windows 2000.
 *
 * Copyright (c) 2001 Andre Guibert de Bruet. <andre@siliconlandmark.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification, immediately at the beginning of the file.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#define USERNAME "Administrator" /* Set this to the system's main user. */
#define PASSWORD ""              /* You want to change this. */
#define REG_HIVE "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon"

int WINAPI
WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
    HKEY currentkey;

	if( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, REG_HIVE, &currentkey ) )
	{
		RegSetValueEx( currentkey, "AutoAdminLogon",  0, REG_SZ, "1", sizeof( "1" ) );
		RegSetValueEx( currentkey, "DefaultUserName", 0, REG_SZ, USERNAME, sizeof( USERNAME ) );
		RegSetValueEx( currentkey, "DefaultPassword", 0, REG_SZ, PASSWORD, sizeof( PASSWORD ) );
		RegCloseKey( currentkey );
	} else
	MessageBox( NULL, "Could not locate registry key!\nThis program is designed for NT-based versions of Windows (2000, XP, 2003, etc).",
			"Auto user logon", MB_OK );
	return 0;
}

/*
 * Compiles with Microsoft Visual C++ 6 and LCC-win32 (Recommended).
 * Place this program in the 'All Users' Startup program group and logout.
 *
 * You can comment out the line with the password if you wish to only have 
 * the name set. This is somewhat more secure, as the password for 
 * autologon is stored in plaintext in the registry. Anyone with the 
 * smallest amount of registry hacking skill could retrieve it.
 *
 * If you choose to comment out the password line, you might want to 
 * seriously consider commenting out the "AutoAdminLogon" line so that you 
 * don't get a series of password failures.
 *
 * Don't say I didn't warn you.
 *
 * Andre Guibert de Bruet   <aguibert@siliconlandmark.com>.
 * Silicon Landmark         http://siliconlandmark.com/staff/andre/
 *
 * Date: 01/31/2001
 */
