Saturday 16 June 2018

How to prompt for ComputerName and UserName before you start an automated Windows Install

By using an XML file, we can automate the installation of Windows 10 in Easy2Boot.

The XML file can have a preset or random UserName and ComputerName, or it can be configured to only have an Administrator account or to prompt for the User Name near the end of the installation process.

For instance, an XML file for SDI_CHOCO could be picked by the user and a fully unattended and automated Windows 10 install would then proceed.

However, it would be useful if we could use the same automated XML file each time we installed it to a different system, but could prompt for a different ComputerName and UserName before we started the installation. This allows us to get a cup of coffee whilst ten different systems are installing without having to come back and enter the UserName half-way through.

See also this later blog post for automatically setting the Serial Number in the ComputerName based on the same method as used in this article.

We can set different values by using grub4dos to modify the XML file before we boot to the ISO...

How to prompt for ComputerName and UserName

Note: The .mnu file has been changed and a grub4dos batch file is now used to replace the strings in the XML file, you no longer need to add lots of spaces to the ends of the lines that you want to modify - see here for more details of the FARXML.g4b and FARKeyXML.g4b batch files and how to use them.


1. Create your automated unattended XML file and place it in the \_ISO\WINDOWS\WIN10 folder - use the WAFG website and XMLtoE2B.exe if you don't want to do it the hard way.

The Username should be set to UNAME and the ComputerName set to PCNAME.

Tip: If the IMAGE/INDEX number is correct, then you will not be prompted to select an Edition, if the INDEX number in the XML file does not match the Product Key, then Setup will highlight the Edition that matches the Product Key and you will have to press ENTER to start the installation - e.g. use an INDEX number or 1 or 8 (depends on ISO) for Win10 Professional with a Win10 Professional Product Key.

2. Edit the XML file so that there are at least twenty spaces at the end of the lines of these 5 entries:

<ComputerName>PCNAME</ComputerName>                    <<<< 20+ spaces here

<Username>UNAME</Username>                    <<<< 20+ spaces here

<FullName>UNAME</FullName>                    <<<< 20+ spaces here

<Name>UNAME</Name>                    <<<< 20+ spaces here

<DisplayName>UNAME</DisplayName>                    <<<< 20+ spaces here


Be sure to add spaces to all the lines (there may be two of each of these in your XML file - one for x86 and one for amd64).

Note: E2B v1.A1 contains a later version of this .mnu file which does not require the XML file to have extra spaces added. It just replaces all occurrences of UNAME and PCNAME.

An example file can be found at "\_ISO\WINDOWS\WIN10\SAMPLE XML FILES\ZZDANGER_Auto_WipeDisk0_Win10ProUK_with_SDI_CHOCO_UNAME_PCNAME.xml" in E2B v1.99 (release version only).

3. Copy the 100KB \AutoUnattend.xml file which can be found in the root of the E2B drive to the \_ISO\WINDOWS\WIN10 folder and rename it as BLANK.XML.

4. Make a .mnu file at \_ISO\MAINMENU\$WIN10_INSTALL.MNU containing the following text:

# BLANK.XML must exist and be larger than your XML file
# Your XML must have UNAME followed by 20 spaces and PCNAME followed by 20 spaces in all relevant lines inside the XML file - e.g.
# <Username>UNAME</Username>(20 spaces here)
# <ComputerName>PCNAME</ComputerName>(20 spaces here)
# <Name>UNAME</Name>(20 spaces here)
# <DisplayName>UNAME</DisplayName>(20 spaces here)
# <FullName>UNAME</DisplayName>(20 spaces here)

#Read more: http://www.easy2boot.com/configuring-e2b/add-windows-install-isos-to-the-main-menu/

iftitle [if exist /_ISO/WINDOWS/WIN10/Windows10x862018_04-02.iso] Install Win10 32-bit\nAutomated install from ISO\nAsk user for ComputerName and UserName
set MFOLDER=/_ISO/WINDOWS/WIN10
set ISO=Windows10x862018_04-02.iso
set XML=ZZDANGER_Auto_WipeDisk0_Win10ProUK_with_SDI_CHOCO_UNAME_PCNAME.xml
#defaults are set here - random username and computername
set UNAME=USER%@TIME:~3,2%%@TIME:~6,2%
set PCNAME=*

if not exist %MFOLDER%/%XML%     pause ERROR: %MFOLDER%/%XML% not found!
if not exist %MFOLDER%/BLANK.XML pause ERROR: %MFOLDER%/BLANK.XML not found!

#note: --locatei maximum string search length 16 characters
cat --locatei="uterName>PCNAME<" %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain string "uterName>PCNAME<"
cat --locatei="<Username>UNAME<" %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain string "<Username>UNAME<"
cat --locatei="splayname>UNAME<" %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain string "Displayname>UNAME<"
cat --locatei="<Name>UNAME</Nam" %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain string "<Name>UNAME</Nam"
cat --locatei="ullName>UNAME</F" %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain string "<FullName>UNAME</F"

cat --locatei="/Username>      " %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain spaces at end of </Username> line
cat --locatei="/ComputerName>  " %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain spaces at end of </ComputerName> line
cat --locatei="/DisplayName>   " %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain spaces at end of </DisplayName> line
cat --locatei="/Name>          " %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain spaces at end of </Name> line
cat --locatei="/FullName>      " %MFOLDER%/%XML% > nul || pause ERROR: %XML% does not contain spaces at end of </FullName> line

#get user input
set /p UNAME=Enter UserName [%UNAME%] : 
echo
set /p PCNAME=Enter ComputerName (no spaces) [%PCNAME%] : 
echo
echo %PCNAME% > (md)0x300+1
cat --locate=\x20 (md)0x300+1 && pause ERROR: ComputerName "%PCNAME%" must not contain spaces!
set PCNAME=%PCNAME%
if %@retval%>=16 pause ERROR: ComputerName "%PCNAME%" must be 1-15 bytes only.


clear
echo
echo %MFOLDER%/%ISO%
echo %MFOLDER%/%XML%
echo UserName=%UNAME%
echo ComputerName=%PCNAME%
echo
#pause Press a key to continue...

debug on
errorcheck on

#fill BLANK.XML with blanks
echo Wipe BLANK.XML
call Fn.24  0x60000 0x20  102400 ;; map (md)0x300+200 (rd) > nul
dd if=(rd)+1 of=()%MFOLDER%/BLANK.XML > nul

#copy XML into BLANK.XML
echo Copy %XML% to BLANK.XML 
dd if=()%MFOLDER%/%XML% of=()%MFOLDER%/BLANK.XML > nul

#change BLANK.XML
echo Change BLANK.XML
cat --locatei="uterName>PCNAME<" --replace="uterName>%PCNAME%</ComputerName>     " ()%MFOLDER%/BLANK.XML > nul || pause ERROR replacing PCNAME with %PCNAME%
cat --locatei="<Username>UNAME<" --replace="<Username>%UNAME%</Username>      "    ()%MFOLDER%/BLANK.XML > nul || pause ERROR replacing UNAME with %UNAME% (Username)
cat --locatei="playName>UNAME</" --replace="playName>%UNAME%</DisplayName>     "   ()%MFOLDER%/BLANK.XML > nul || pause ERROR replacing UNAME with %UNAME% (DisplayName)
cat --locatei="<Name>UNAME</Nam" --replace="<Name>%UNAME%</Name>     "             ()%MFOLDER%/BLANK.XML > nul || pause ERROR replacing UNAME with %UNAME% (Name)
cat --locatei="<FullName>UNAME<" --replace="<FullName>%UNAME%</FullName>     "     ()%MFOLDER%/BLANK.XML > nul || pause ERROR replacing UNAME with %UNAME% (FullName)

#check it worked - Note: only works if names are less than 15 characters (search string max = 16)
#comment out these lines if you use names longer than 15 characters
echo Check BLANK.XML
cat --locate=">%UNAME%"  %MFOLDER%/BLANK.XML > nul || pause ERROR: %XML% does not contain ">%UNAME%"
cat --locate=">%PCNAME%"  %MFOLDER%/BLANK.XML > nul || pause ERROR: %XML% does not contain ">%PCNAME%"

echo
pause If all seems OK - press a key to start the install...

/%grub%/RunWin8.g4b  %MFOLDER% BLANK.XML
boot


You can download the .mnu file here.
It does not need to be in the MAINMENU menu folder and can be any name you wish. It will not work in the \_ISO\WINDOWS\WIN10 folder however - it must go in a standard E2B menu folder or you can create a new menu subfolder using the E2B sub-menu maker script..

5. Edit the .MNU file to contain the correct name of your Windows 10 ISO and XML file. You can set a default ComputerName and UserName if you wish. You can also change the menu entry (iftitle) text if you wish.

The ISO and XML files must be in the same folder (as specified by MFOLDER).


To start an installation, choose the Main menu entry, you will be prompted for the ComputerName and UserName and then the XML file will be changed for you.


Names longer than 14 characters may cause an error to be reported by the grub4dos code.

Use * for the ComputerName if you want Windows Setup to choose a random name for you.
The official MS docs say:
This random name will have at most eight characters from the RegisteredOwner and/or RegisteredOrganization strings plus some random characters. If RegisteredOwner is blank, the username may be used instead. Usually the RegisteredOwner and RegisteredOrganization fields are set to the same value - e.g. Acme-. Spaces and strange characters are not allowed - 15 bytes max.
However, when I tested it, it seems to first use up to the first seven characters from <FullName> and then any remaining characters from <Organization> in the <UserData> section of the XML file, e.g.

ComputerName=*
FullName=UF552
Organization=E2B
Result >>> Computer name is set to UF552E2-N42R1CJ

ComputerName=*
FullName=abcdefgh
Organization=E2B
Result >>> Computer name is set to ABCDEFG-SOSPB3N




Note that the .mnu file does some rudimentary checking, but you should ensure that you have at least 20 spaces on the end of the relevant XML lines and you have used "PCNAME" and "UNAME" on the all the correct lines inside your XML file.

If there are any problems, examine the BLANK.XML file.
Also check the C:\WINDOWS\PANTHER\setupact.log file and the C:\WINDOWS\PANTHER\UNATTENDGC\setupact.log file for error messages.

Good luck!

No comments:

Post a Comment