This guide aims to teach people with basic computer skills to flash factory firmware image on Nexus 7  using Windows 7/10. It should apply to other modern stock Android devices.
Note: To prevent unauthorized access, unlocking the bootloader will delete all personal data on the device. Therefore, you must backup important data first before proceeding with the following procedure.
1. Follow the instructions here to install Android SDK Tools in Windows.
On the SDK Manager window that pops up, check the following two packages:
- Tools > Android SDK Platform-tools
- Extras > Google USB Driver
Now click "Install packages...". Check the "Accept License" radio box, and then click the "Install" button to install the selected packages.
Write down the SDK Path which is displayed under the menu bar of the Android SDK Manager. For example, the Android SDK Path in my installation is: C:\Users\wenzhuo\AppData\Local\Android\android-sdk.
2. Install 7-Zip if it's not already installed in your computer. We'll use it to extract the factory images.
2. Right-click the firmware image file (razor*.tgz) you just downloaded, and then click "7-Zip > Extract here" on the context menu. You'll now have a razor*.tar file in the current directory. Do it again on the tar file, and you'll have a new directory "razor*" in the current directory. In my case, the new directory is named "razorg-mmb29o". Hold the Shift key on the keyboard, and right-click on the directory name, and click "Open command window here" on the context menu, you'll have a Command Prompt window opened with the current working directory in the extracted factory image directory.
3. On your Nexus 7, open Settings > About phone and tap Build number seven times to enable Developer options. Return to the previous screen to find Developer options at the bottom. Turn on the "USB debugging" feature in the Developer options.
4. Connect your Nexus 7 to your computer using a Micro-USB cable.
5. In the Command Prompt window opened in Step 2, add the platform-tools direcotry, which is a subdirectory in the Android SDK Path directory, to the PATH environment variable.
> set PATH=C:\Users\wenzhuo\AppData\Local\Android\android-sdk\platform-tools;%PATH%
6. Reboot Nexus 7 into fastboot mode by typing the following command in the Command Prompt:
> adb reboot bootloader
You'll see an "Allow USB debugging?" prompt on your device. Check "Always allow from this computer" and then tap OK. Type "adb reboot bootloader" command again in the Command Prompt, and your Nexus 7 will reboot into the fastboot mode this time.
7. Unlock the device's bootloader by running:
> fastboot oem unlock
The device will show you a confirmation screen. Unlocking the bootloader will erase all personal data on the device. Press the Volume-Up button to select Yes and then press the Power button to go ahead unlocking the bootloader.
8. Now flash the factory firmware by running the flash-all.bat script in the Command Prompt:
Once the script finishes, your device will reboot.
9. After reconfiguring your device, lock the bootloader again for security:
> adb reboot bootloader > fastboot oem lock
You can also disable the USB debugging feature in the Developer options.