One problem that comes up now and again for any OS (well, any modern OS) is how to recover administrative access to the system when the password has been forgotten.
There’s a reasonably straightforward solution  for Windows 7, which I haven’t seen on the web so far, so I thought I should publish it. Be aware that I can’t offer or provide any warranty, support, or assistance with this procedure, apart perhaps from clarifying any part of the instructions that aren’t clear. It’s always worked for me, but that’s all I can promise.
Additional note 13 June 2012: see also this question on superuser.com, which provides a number of alternatives.
This procedure also works on Windows Vista; the underlying technique works on Windows XP as well but is not usually feasible because the Windows XP install CD does not contain a command-line recovery option.
One important caveat: since this resets the password rather than letting you find out what it is, any encrypted files belonging to the user will be permanently lost.
This is the short version, for advanced users and sysadmins:
- Boot to Windows 7 from the installation or repair DVD, or from Windows PE 3 boot media, or from a Windows 7 installation on another HDD. If the target OS is Vista, use the Vista installation DVD, or Windows PE 2, or another Vista installation. (Booting to a mismatched version of Windows might work, but I’ve never tried it; if the registry file formats aren’t exactly the same between versions, this could result in a corrupted registry and an unbootable system.)
- Load the SYSTEM registry hive from the target OS. Back it up first.
- In the Setup key, change SetupType to 2 and CmdLine to cmd.exe.
- Boot the target OS. You’ll get a command-line window in system context.
The long version, for everyone else:
- Boot to your Windows 7 or Windows Vista installation DVD, whichever matches the installed OS. If you purchased your computer from a responsible vendor, they’ll have provided you with one, although unfortunately many vendors don’t.
Additional note 8 September 2011: In Windows 7, there is an option in the Start Menu (under Maintenance) to Create a System Repair Disc. The CD or DVD this option creates is perfect for the job. However, you have to be an administrator to use it, so unless you’ve done it ahead of time or can use a friend’s Windows 7 machine you’re out of luck.
Additional note 1 September 2011: If your computer is 64-bit capable (you don’t need to actually be running a 64-bit OS) then you can use the install disk for Microsoft’s free server product, Hyper-V. You can find it here. Note, however, that it is a fairly big download, a little more than a gigabyte.
Additional note 5 May 2011: Nommo was kind enough to point me to this post on Microsoft Answers which provides a link to downloadable repair disks for Vista and Windows 7. I can’t from my own knowledge confirm that these disks are legitimate, and Microsoft aren’t telling, so use only at your own risk. Indications are that they are probably OK. (Personally, I wouldn’t use the charged-download option until I’d checked how much my OEM was going to charge to provide an installation disk. Make sure the OEM knows you need a Windows installation disk, not a system recovery disk.)
A vendor system recovery disk might offer the same functionality, and in some cases you can order an installation DVD from your vendor (or from Microsoft?).
- Select your language options on the first screen and press Next to continue.
- Choose “Repair Your Computer”.
- Choose “Use recovery tools…” and select your OS. Make a note of which drive letter it is on, e.g., C: or D:. This might not be the same drive letter you see when booted normally.
Additional note 1 September 2011: if you get an error message when you press Next, this might be because the install disk you are using is not compatible with the version of Windows you have installed. This will happen, for example, if you are using the Hyper-V install disk. Don’t panic. Just press SHIFT-F10 to open a command prompt and skip ahead to step 6.
- Select Command Prompt.
- In the command prompt window that appears, type “regedit” and press ENTER.
- Select HKEY_LOCAL_MACHINE and then choose Load Hive from the File menu.
- Find and open the file named SYSTEM on the drive you noted in step 4. If Windows is in the default configuration, this will be in windows\system32\config.
- Enter a key name, e.g., “xxx”.
- Click the plus icon to the left of HKEY_LOCAL_MACHINE to open this key. Select the xxx key.
- Select Export from the File Menu. Change the Save as type to Registry Hive Files. Type a name for the backup, for example, systembackup, and press Save. (This step creates a backup of the unmodified SYSTEM registry hive as a precaution.)
- Open the xxx key, and select Setup.
- Double-click on SetupType in the right-hand pane. Enter 2 and press OK.
- Double-click on CmdLine. Enter cmd.exe and press OK.
- Close Registry Editor. Type “regedit” and press ENTER to open it again. (This step does not appear to be necessary in Windows 7, but in Windows Vista if you do not do this the next step might fail with an Access Denied error.)
- Open HKEY_LOCAL_MACHINE, select xxx, and choose Unload Hive from the File Menu. Push Yes.
- Close the command window and the Registry Editor. Remove the installation DVD and select Restart.
- When your computer boots up, another command window should appear.
- Type “net user foo bar”, replacing foo with the username of the account whose password you want to reset, and bar with the new password. For example, you might type “net user Administrator letmein”. Press ENTER.
- If you want to use the built-in Administrator account, you will probably need to enable it: type “net user Administrator /active:yes” and press ENTER.
- If you don’t know what the administrative username(s) are, type “net localgroup administrators” and press ENTER to find out.
- Type “exit” and press ENTER.
- When the logon screen appears, use the username and the new password to log in.
Note that if the entire disk is encrypted, this procedure will not work at all. System administrators who want to prevent users from using techniques like this one to reset passwords should consider disk encryption.  Another option is to configure the system BIOS to disallow booting from removable media, although if the user can open the case of the machine this can usually be reset.
Hope this helps.
 Well, for some definitions of straightforward, anyway.
 I’ve heard tell of some administrators whose “solution” to this issue is to use the network firewall to block access to any web sites with instructions on resetting passwords! Whether they also inspect all printed material entering the building, and ban anybody they think might be smart enough to just remember how to do it, I don’t know.