Monday, 20 August 2018

E2B v1.A1i/j Beta now available

This 1.A1j version now includes revised versions of the two .mnu files:

\_ISO\docs\Sample mnu files\Windows\WIN10_Prompt_for_PCNAME_and_UNAME.mnu
\_ISO\docs\Sample mnu files\Windows\WIN10_Prompt_for_UNAME_auto_serial_COMPNAME.mnu

and also makes use of a new grub4dos batch file farxml.g4b (find-and-replace in XML).

farxml.g4b accepts three input parameters:

  • source #1: Full path to source of XML data - e.g. ()/_ISO/Win10Prox64.XML  or %MEM%.
  • findstr  #2: Search string value to find inside the XML file - can be enclosed in double-quotes, must be 16 characters or less, can be partial string, is case-sensitive.
  • replstr  #3: String to use as replacement - can be enclosed in double-quotes and can contain spaces.

For instance, if the XML file contained an XML key value of 123ABC456, then the findstr parameter can be any part of the value such as 3ABC or ABC456 or the full string 123ABC456, and the whole value of 123ABC456 will replaced by the replstr.

e.g. in the case of   <ComputerName>123ABC456</ComputerName>

farxml will find the > character before the match and the < character after the match and then replace all the characters in-between the symbols > and < with the replstr string.

The changed output is kept in memory at (md)0x20000+0xc8 and on exit, the MEM variable is set by farxml.g4b to be this memory block also - i.e.  grub4dos variable is set:

set MEM=(md)0x20000+0xc8

Note that it only works for XML format files because farxml.g4b only replaces XML values (e.g. >123ABC456< is a value field), you cannot use it to change other parts of an XML file or it will fail to work correctly.

Here are some example lines using farxml.g4b from one of the .mnu files:

set UNAME=Steve's PC

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

#replace string values in XML files
/%grub%/farxml.g4b ()%MFOLDER%/%XML% PCNAME %PCNAME%
#result is in %MEM% = (md)0x200000+0x100
/%grub%/farxml.g4b %MEM% UNAME "%UNAME%"
#copy result into BLANK.XML
dd if=%MEM% of=()%MFOLDER%/BLANK.XML > nul

The big advantage of using farxml.g4b is that now the source XML does not need to have lots of spaces added to the end of the XML lines that are going to be altered. You can just use any XML file and change the value fields that you want to modify later using farxml.g4b.

For instance, the code above will replace all occurrences of the string values of "PCNAME" and "UNAME" wherever they occur in the XML file and will write the resultant XML data in memory at %MEM% to the file BLANK.XML. It assumes that "PCNAME" and "UNAME" are unique strings in the XML file and there can be multiple instances. The file BLANK.XML can then be used as the autounattend.xml file for Setup.

We do not alter the source XML file because we would not be able to use the same XML file  again once the strings have been replaced - hence we use a temporary BLANK.XML file.

The XML file and the ISO need to be in the same folder.

See the .mnu files for more details and the complete code.


I have also added a similar batch file called FARKeyXML.g4b into v1.A1j. It has a similar action but will search for a key name and then replace its value.

.e.g. Using this XML file


All these are equivalent and will replace USER1 with NEWUSER

/%grub%/FARKeyXML.g4b ()/MyFile.XML <DisplayName>      NEWUSER
/%grub%/FARKeyXML.g4b ()/MyFile.XML DisplayName>       NEWUSER
/%grub%/FARKeyXML.g4b ()/MyFile.XML DisplayName        NEWUSER
/%grub%/FARKeyXML.g4b ()/MyFile.XML layNam             NEWUSER
/%grub%/FARKeyXML.g4b ()/MyFile.XML \n<DisplayName>    NEWUSER
/%grub%/FARKeyXML.g4b ()/MyFile.XML "\n<DisplayName>"  NEWUSER

Note that the key name must be unique, so beware of key names such as <Value> or <Key> which may occur in several different sections inside the XML file and each may have different significance.

In particular <ProductKey> cannot be used as a key name with FARKeyXML.g4b because it may appear twice in the XML file, once with a value field and once without a value field (that's Microsoft for you!):

and also

So if you attempt to add a value for <ProductKey> of say AAAAA-AAAAA-AAAAA-AAAAA-AAAAAA, then you will get:

which is correct but also
which is incorrect and will result in a Setup Unattend error!

More examples...

/%grub%/farkeyxml.g4b %MEM% "<DisplayName>" "My Display Name"
/%grub%/farkeyxml.g4b %MEM% "\n<Key>" "ZZZZZ-ZZZZZ-ZZZZZ-ZZZZZ-ZZZZZ"
/%grub%/farkeyxml.g4b %MEM% "<FullName>" "My Full Name"
# no spaces in ComputerName and must be <16 characters...
/%grub%/farkeyxml.g4b %MEM% "uterName>" "My_PC"

Code extract from WIN10_Prompt_User_for_XML_settings.mnu

This .mnu file does not need a specially prepared XML file and it prompts the user to enter various XML fields manually before starting the build...

set ask=
set /p ask=Enter DisplayName : 
# First usage must use ()%MFOLDER%/%XML% as source - following lines must use %MEM%
if exist ask /%grub%/farkeyxml.g4b ()%MFOLDER%/%XML% "DisplayName>" "%ask%"
# whole XML file is now in %MEM%

set ask=
set /p ask=Enter FullName : 
if exist ask /%grub%/farkeyxml.g4b %MEM% "<FullName>" "%ask%"

set ask=
set /p ask=Enter RegisteredOrganization : 
if exist ask /%grub%/farkeyxml.g4b %MEM% "redOrg" "%ask%"

set ask=
set /p ask=Enter RegisteredOwner : 
if exist ask /%grub%/farkeyxml.g4b %MEM% "redOwner>" "%ask%"

# Local account name
/%grub%/farkeyxml.g4b %MEM% "<Name>" "%UNAME%"

# for autologon name
/%grub%/farkeyxml.g4b %MEM% "<UserName>" "%UNAME%"
/%grub%/farkeyxml.g4b %MEM% "<Username>" "%UNAME%"

# ComputerName
/%grub%/farkeyxml.g4b %MEM% "uterName>" "%PCNAME%"

# change Product Key - key must start with "ASKME-"
if exist KEY cat --locatei="Key>ASKME-" --replace="Key>%KEY%"  %MEM% > nul
# or W269N-
if exist KEY cat --locatei="Key>W269N-" --replace="Key>%KEY%"  %MEM% > nul

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