Saturday, July 29, 2017

autounattend xml file generation with vbs wsh

Hi,

This script will:
read 2 of 3 files:
SynchronousCommand01_maison.txt
SynchronousCommand02_job.txt
SynchronousCommand03_common.txt
and generate a 64 bits autounattend.xml file in same folder as the script

If config01 is equal to 1, common and job files will be used to generate the autounattend.xml
If config01 is equal to 2, common and maison files will be used.

The 3 input files should look like this (3 lines for each synchronous command)

===== SynchronousCommand03_common.txt ======
1
powershell permission remotesigned
reg add HKCU\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ /v ExecutionPolicy /t Reg_SZ /d "RemoteSigned" /f
3
7zip
cmd /c c:\_appsall\7zip\commandline.bat
1
explorer open in this PC
REG ADD "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" /v LaunchTo /t REG_DWORD /d 1 /f
====== end of file ======

You can change in the script (with notepad) the value config01 to inrtegrate "maison" (config01 = 1) or job (config01 = 2)

It is for 64 bits only, but you can change it for 32 bits (x86) in an array (it used to generate the file for both, but i had an issue where the synchronous commands were executed twice in 64 bits.



'=== autounattend.vbs
'=== autounattend.xml file generator for windows 10 1703

'=== by sergefournier@hotmail.com 2017-06-20

'=== save thsi script as: csv2xml.VBS
'=== input file must be sample1.csv in the same directory as the script (same folder)
'=== outputfile will be sampleout1.xml
'=== zzz_troubleshooting.txt will tell you what was not processed (lines)

'=== support 2 carriage return in a field, but not 3 :P

Set objFSO    = CreateObject("Scripting.FileSystemObject")

'=== actual drive, actual directory, and "\"
thepath=WScript.ScriptFullName
p = instrRev(thepath,"\")
basedir  = left(thepath,p)
filnam = right(thepath,len(thepath)-p)

logall = 1

if logall=1 then
   '=== debug log
   logfile01 = basedir & filnam & "_log.txt"
   on error resume next
   Set Fil02 = objFSo.OpenTextFile(logfile01, 2, true)
   on error goto 0
end if

if logall=1 then
   fil02.WriteLine date & " " & time & " START"
end if

filenamefullxml02 = basedir & "autounattend.xml"
'=== 1 = maison
'=== 2 = job
config01 = 2

'=== spaces in xml name are not good

quebec01 = 1

if quebec01 = 0 then
UILanguage01 = "en-US"
InputLocale01 = "0426:00010426"
SystemLocale01 = UILanguage01
UILanguage02 = UILanguage01
UILanguageFallback01 = UILanguage01
UserLocale01 = UILanguage01
else
  '=== winpe and preload (france only)
UILanguage01 = "fr-FR"
InputLocale01 = "0c0c:00001009"
SystemLocale01 = UILanguage01
UILanguage02 = UILanguage01
UILanguageFallback01 = UILanguage01
UserLocale01 = "fr-CA"

  '=== windows 10
UILanguage11 = "fr-CA"
InputLocale11 = "0c0c:00001009"
SystemLocale11 = UILanguage11
UILanguage12 = UILanguage11
UILanguageFallback11 = UILanguage11
UserLocale11 = UILanguage11

end if

'=== userdate
if config01 = 1 then
'=== home
fullname01 = "Maison"
else
fullname01 = "Utilisateur"
end if

username01 = fullname01

organization01 = ""

productkey01 = "W269N-WFGWX-YVC9B-4J6C9-T83GX"
enablefirewall01 = "true"

  '1 Specifies the recommended level of protection for your computer.
  '2 Specifies that only updates are installed.
  '3 Specifies that automatic protection is disabled.
if config01 = 1 then
'=== home
NetworkLocation01 = "Home"
protectyourpc01 = "2"
else
NetworkLocation01 = "Work"
protectyourpc01 = "3"
end if

password01 = ""
'=== localaccount
description01 = "Utilisateuradmin"
displayname01 = fullname01
group01= "Administrators"
name01 = fullname01

RegisteredOrganization01 = ""
registredowner01 = ""

computername01 = ""

timezone01 = "Eastern Standard Time"

installfromtag01 = 1 '=== put install from to choose an image index in WIM
installtotag01 = 0 '=== put installto to choose disk 0 partition 0

archs01 = array("amd64") '=== architecture
'archs01 = array("x86", "amd64") '=== architecture

'=== create xml
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
Set objIntro = xmlDoc.createProcessingInstruction("xml","version='1.0' encoding='UTF-8'")
xmlDoc.insertBefore objIntro,xmlDoc.childNodes(0)

Set objxmlchild01 = xmlDoc.createElement("unattend")
objxmlchild01.SetAttribute "xmlns", "urn:schemas-microsoft-com:unattend"
xmlDoc.appendChild objxmlchild01

Set objxmlchild02 = xmlDoc.createElement("settings")
objxmlchild02.SetAttribute "pass", "windowsPE"
objxmlchild01.appendChild objxmlchild02
 
    '=== Microsoft-Windows-International-Core-WINPE
    for each arch01 in archs01
 
      Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-International-Core-WinPE"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

Set objxmlchild04 = xmlDoc.createElement("SetupUILanguage")
objxmlchild03.appendChild objxmlchild04

'=== france setup cause canada does not exist in winpe
Set objxmlchild05 = xmlDoc.createElement("UILanguage")
objxmlchild05.text = UILanguage01
objxmlchild04.appendChild objxmlchild05

Set objxmlchild04 = xmlDoc.createElement("InputLocale")
objxmlchild04.text = InputLocale01
objxmlchild03.appendChild objxmlchild04

Set objxmlchild04 = xmlDoc.createElement("SystemLocale")
objxmlchild04.text = SystemLocale01
objxmlchild03.appendChild objxmlchild04
Set objxmlchild04 = xmlDoc.createElement("UILanguage")
objxmlchild04.text = UILanguage02
objxmlchild03.appendChild objxmlchild04
Set objxmlchild04 = xmlDoc.createElement("UILanguageFallback")
objxmlchild04.text = UILanguageFallback01
objxmlchild03.appendChild objxmlchild04
Set objxmlchild04 = xmlDoc.createElement("UserLocale")
objxmlchild04.text = UserLocale01
objxmlchild03.appendChild objxmlchild04

    next

'===Microsoft-Windows-Setup
for each arch01 in archs01
Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-Setup"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

         
Set objxmlchild04 = xmlDoc.createElement("ImageInstall")
objxmlchild03.appendChild objxmlchild04

Set objxmlchild05 = xmlDoc.createElement("OSImage")
objxmlchild04.appendChild objxmlchild05
         
            if installfromtag01 = 1 then
         
            '=== choose image in index1 in dvd (wim index)
Set objxmlchild06 = xmlDoc.createElement("InstallFrom")
objxmlchild05.appendChild objxmlchild06

Set objxmlchild07 = xmlDoc.createElement("MetaData")
objxmlchild07.SetAttribute "wcm:action", "add"
objxmlchild06.appendChild objxmlchild07

                Set objxmlchild08 = xmlDoc.createElement("Value")
                objxmlchild08.text = "1"
                objxmlchild07.appendChild objxmlchild08

                Set objxmlchild08 = xmlDoc.createElement("key")
                objxmlchild08.text = "/IMAGE/INDEX"
                objxmlchild07.appendChild objxmlchild08
            end if
         
            '=== installto
if installtotag01 = 1 then

Set objxmlchild06 = xmlDoc.createElement("InstallTo")
objxmlchild05.appendChild objxmlchild06

Set objxmlchild07 = xmlDoc.createElement("DiskID")
objxmlchild07.text = "0"
objxmlchild06.appendChild objxmlchild07

Set objxmlchild07 = xmlDoc.createElement("PartitionID")
objxmlchild07.text = "1"
objxmlchild06.appendChild objxmlchild07
end if

Set objxmlchild06 = xmlDoc.createElement("InstallToAvailablePartition")
objxmlchild06.text = "false"
objxmlchild05.appendChild objxmlchild06

Set objxmlchild06 = xmlDoc.createElement("WillShowUI")
objxmlchild06.text = "OnError"
objxmlchild05.appendChild objxmlchild06

Set objxmlchild04 = xmlDoc.createElement("UserData")
objxmlchild03.appendChild objxmlchild04

Set objxmlchild05 = xmlDoc.createElement("AcceptEula")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("FullName")
objxmlchild05.text = fullname01
objxmlchild04.appendChild objxmlchild05

if len(Organization01) > 0 then
Set objxmlchild05 = xmlDoc.createElement("Organization")
objxmlchild05.text = organization01
objxmlchild04.appendChild objxmlchild05
          end if

Set objxmlchild05 = xmlDoc.createElement("ProductKey")
objxmlchild04.appendChild objxmlchild05

Set objxmlchild06 = xmlDoc.createElement("Key")
objxmlchild06.text = productkey01
objxmlchild05.appendChild objxmlchild06

Set objxmlchild04 = xmlDoc.createElement("EnableFirewall")
objxmlchild04.text = enablefirewall01
objxmlchild03.appendChild objxmlchild04

next

'=== Microsoft-Windows-LUA-Settings
for each arch01 in archs01

Set objxmlchild02 = xmlDoc.createElement("settings")
objxmlchild02.SetAttribute "pass", "offlineServicing"
objxmlchild01.appendChild objxmlchild02

Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-LUA-Settings"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

Set objxmlchild04 = xmlDoc.createElement("EnableLUA")
objxmlchild04.text = "false"
objxmlchild03.appendChild objxmlchild04
next

'=== Microsoft-Windows-Security-SPP
for each arch01 in archs01

Set objxmlchild02 = xmlDoc.createElement("settings")
objxmlchild02.SetAttribute "pass", "generalize"
objxmlchild01.appendChild objxmlchild02

Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-Security-SPP"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

Set objxmlchild04 = xmlDoc.createElement("SkipRearm")
objxmlchild04.text = "1"
objxmlchild03.appendChild objxmlchild04

next

    '=== Microsoft-Windows-International-Core
 
 
Set objxmlchild02 = xmlDoc.createElement("settings")
objxmlchild02.SetAttribute "pass", "specialize"
objxmlchild01.appendChild objxmlchild02

    for each arch01 in archs01
Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-International-Core"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

'=== canada quebec setup language here
Set objxmlchild04 = xmlDoc.createElement("InputLocale")
objxmlchild04.text = InputLocale11
objxmlchild03.appendChild objxmlchild04

Set objxmlchild04 = xmlDoc.createElement("SystemLocale")
objxmlchild04.text = SystemLocale11
objxmlchild03.appendChild objxmlchild04
Set objxmlchild04 = xmlDoc.createElement("UILanguage")
objxmlchild04.text = UILanguage12
objxmlchild03.appendChild objxmlchild04
Set objxmlchild04 = xmlDoc.createElement("UILanguageFallback")
objxmlchild04.text = UILanguageFallback11
objxmlchild03.appendChild objxmlchild04
Set objxmlchild04 = xmlDoc.createElement("UserLocale")
objxmlchild04.text = UserLocale11
objxmlchild03.appendChild objxmlchild04

next

'=== Microsoft-Windows-Security-SPP-UX

      for each arch01 in archs01
   
Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-Security-SPP-UX"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

Set objxmlchild04 = xmlDoc.createElement("SkipAutoActivation")
objxmlchild04.text = "true"
objxmlchild03.appendChild objxmlchild04
   
      next
   
      '=== Microsoft-Windows-SQMApi
   
      for each arch01 in archs01

Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-SQMApi"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

Set objxmlchild04 = xmlDoc.createElement("CEIPEnabled")
objxmlchild04.text = "0"
objxmlchild03.appendChild objxmlchild04

      next

'=== Microsoft-Windows-Shell-Setup"

for each arch01 in archs01

Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-Shell-Setup"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

if len(computername01)<>0 then
Set objxmlchild04 = xmlDoc.createElement("ComputerName")
objxmlchild04.text = computername01
objxmlchild03.appendChild objxmlchild04
        end if

Set objxmlchild04 = xmlDoc.createElement("ProductKey")
objxmlchild04.text = productkey01
objxmlchild03.appendChild objxmlchild04

      next

    '=== oobeSystem

Set objxmlchild02 = xmlDoc.createElement("settings")
objxmlchild02.SetAttribute "pass", "oobeSystem"
objxmlchild01.appendChild objxmlchild02

    for each arch01 in archs01
 
Set objxmlchild03 = xmlDoc.createElement("component")
objxmlchild03.SetAttribute "name", "Microsoft-Windows-Shell-Setup"
objxmlchild03.SetAttribute "processorArchitecture", arch01
objxmlchild03.SetAttribute "publicKeyToken", "31bf3856ad364e35"
objxmlchild03.SetAttribute "language", "neutral"
objxmlchild03.SetAttribute "versionScope", "nonSxS"
objxmlchild03.SetAttribute "xmlns:wcm", "http://schemas.microsoft.com/WMIConfig/2002/State"
objxmlchild03.SetAttribute "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"
objxmlchild02.appendChild objxmlchild03

Set objxmlchild04 = xmlDoc.createElement("AutoLogon")
objxmlchild03.appendChild objxmlchild04

Set objxmlchild05 = xmlDoc.createElement("Password")
objxmlchild04.appendChild objxmlchild05

Set objxmlchild06 = xmlDoc.createElement("Value")
objxmlchild06.text = password01
objxmlchild05.appendChild objxmlchild06

Set objxmlchild06 = xmlDoc.createElement("PlainText")
objxmlchild06.text = "true"
objxmlchild05.appendChild objxmlchild06

Set objxmlchild05 = xmlDoc.createElement("Enabled")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("Username")
objxmlchild05.text = username01
objxmlchild04.appendChild objxmlchild05

Set objxmlchild04 = xmlDoc.createElement("OOBE")
objxmlchild03.appendChild objxmlchild04

Set objxmlchild05 = xmlDoc.createElement("HideEULAPage")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("HideOEMRegistrationScreen")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("HideOnlineAccountScreens")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("HideWirelessSetupInOOBE")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("NetworkLocation")
objxmlchild05.text = NetworkLocation01
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("SkipUserOOBE")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("SkipMachineOOBE")
objxmlchild05.text = "true"
objxmlchild04.appendChild objxmlchild05

Set objxmlchild05 = xmlDoc.createElement("ProtectYourPC")
objxmlchild05.text = ProtectYourPC01
objxmlchild04.appendChild objxmlchild05

Set objxmlchild04 = xmlDoc.createElement("UserAccounts")
objxmlchild03.appendChild objxmlchild04

Set objxmlchild05 = xmlDoc.createElement("LocalAccounts")
objxmlchild04.appendChild objxmlchild05

Set objxmlchild06 = xmlDoc.createElement("LocalAccount")
objxmlchild06.SetAttribute "wcm:action", "add"
objxmlchild05.appendChild objxmlchild06

Set objxmlchild07 = xmlDoc.createElement("Password")
objxmlchild07.text = password01
objxmlchild06.appendChild objxmlchild07

Set objxmlchild08 = xmlDoc.createElement("Value")
objxmlchild08.text = password01
objxmlchild07.appendChild objxmlchild08

Set objxmlchild08 = xmlDoc.createElement("PlainText")
objxmlchild08.text = "true"
objxmlchild07.appendChild objxmlchild08

Set objxmlchild07 = xmlDoc.createElement("Description")
objxmlchild07.text = description01
objxmlchild06.appendChild objxmlchild07

Set objxmlchild07 = xmlDoc.createElement("DisplayName")
objxmlchild07.text = displayname01
objxmlchild06.appendChild objxmlchild07

Set objxmlchild07 = xmlDoc.createElement("Group")
objxmlchild07.text = group01
objxmlchild06.appendChild objxmlchild07

Set objxmlchild07 = xmlDoc.createElement("Name")
objxmlchild07.text = name01
objxmlchild06.appendChild objxmlchild07

if len(RegisteredOrganization01)>0 then
Set objxmlchild04 = xmlDoc.createElement("RegisteredOrganization")
objxmlchild04.text = RegisteredOrganization01
objxmlchild03.appendChild objxmlchild04
        end if
     
        if len(RegistredOwner01)>0 then
Set objxmlchild04 = xmlDoc.createElement("RegisteredOwner")
objxmlchild04.text = RegistredOwner01
objxmlchild03.appendChild objxmlchild04
        end if
     
Set objxmlchild04 = xmlDoc.createElement("DisableAutoDaylightTimeSet")
objxmlchild04.text = "false"
objxmlchild03.appendChild objxmlchild04

Set objxmlchild04 = xmlDoc.createElement("FirstLogonCommands")
objxmlchild03.appendChild objxmlchild04

d = firstlogoncommands(objxmlchild04)

Set objxmlchild04 = xmlDoc.createElement("TimeZone")
objxmlchild04.text = timezone01
objxmlchild03.appendChild objxmlchild04
   
      next

'=== 64 bits

fil02.WriteLine date & " " & time & " Saving xml file: " & filenamefullxml02

xmlDoc.Save filenamefullxml02

fil02.WriteLine date & " " & time & " END"

fil02.close


'=======================================


function firstlogoncommands(objxmlchild04)

order01 = 0

filenamefull01 = basedir & "SynchronousCommand03_common.txt"
fil02.WriteLine date & " " & time & " common synchronous commands: " & filenamefull01
Set File01 = objFSo.OpenTextFile(filenamefull01, 1, true)

'=== read filed names (1st line)
  totline01 = 0
Do While file01.AtEndOfStream <> True
err01 = 0: err02 = "": on error resume next
line01 = file01.readline
line02 = file01.readline
line03 = file01.readline
err01 = err.number: err02 = err.message: on error goto 0

if err01 = 0 then
      err01 = 0: err02 = "": on error resume next
      line01 = line01 + 1 '=== check if it is a number
      err01 = err.number: err02 = err.message: on error goto 0
   
      if err01 = 0 then
        totline01 = totline01 + 3
        Set objxmlchild05 = xmlDoc.createElement("SynchronousCommand")
        objxmlchild05.SetAttribute "wcm:action", "add"
        objxmlchild04.appendChild objxmlchild05

          Set objxmlchild06 = xmlDoc.createElement("Description")
          objxmlchild06.text = line02
          objxmlchild05.appendChild objxmlchild06

          Set objxmlchild06 = xmlDoc.createElement("Order")
          order01 = order01 + 1
          objxmlchild06.text = order01
          objxmlchild05.appendChild objxmlchild06

          Set objxmlchild06 = xmlDoc.createElement("CommandLine")
          objxmlchild06.text = line03
          objxmlchild05.appendChild objxmlchild06

          Set objxmlchild06 = xmlDoc.createElement("RequiresUserInput")
          objxmlchild06.text = "false"
          objxmlchild05.appendChild objxmlchild06
      else
        fil02.WriteLine date & " " & time & " ERROR data integrity, need 1 number, description, command: " & totline01
      end if
    else
      fil02.WriteLine date & " " & time & " ERROR reading line at: " & totline01
    end if
loop
file01.close

if config01 = 1 then
filenamefull02 = basedir & "SynchronousCommand01_maison.txt"
elseif config01 = 2 then
filenamefull02 = basedir & "SynchronousCommand02_job.txt"
end if

fil02.WriteLine date & " " & time & " maison or job synchronous commands: " & filenamefull02
Set File02 = objFSo.OpenTextFile(filenamefull02, 1, true)

'=== read filed names (1st line)
  totline01 = 0
Do While file02.AtEndOfStream <> True

err01 = 0: err02 = "": on error resume next
line01 = file02.readline
line02 = file02.readline
line03 = file02.readline
err01 = err.number: err02 = err.message: on error goto 0
   
    if err01 = 0 then
      err01 = 0: err02 = "": on error resume next
      line01 = line01 + 1 '=== check if it is a number
      err01 = err.number: err02 = err.message: on error goto 0
   
      if err01 = 0 then  
        totline01 = totline01 + 3
        Set objxmlchild05 = xmlDoc.createElement("SynchronousCommand")
        objxmlchild05.SetAttribute "wcm:action", "add"
        objxmlchild04.appendChild objxmlchild05
       
          Set objxmlchild06 = xmlDoc.createElement("Description")
          objxmlchild06.text = line02
          objxmlchild05.appendChild objxmlchild06
   
          Set objxmlchild06 = xmlDoc.createElement("Order")
          order01 = order01 + 1
          objxmlchild06.text = order01
          objxmlchild05.appendChild objxmlchild06
   
          Set objxmlchild06 = xmlDoc.createElement("CommandLine")
          objxmlchild06.text = line03
          objxmlchild05.appendChild objxmlchild06
   
          Set objxmlchild06 = xmlDoc.createElement("RequiresUserInput")
          objxmlchild06.text = "false"
          objxmlchild05.appendChild objxmlchild06
      else
        fil02.WriteLine date & " " & time & " ERROR data integrity, need 1 number, description, command: " & totline01
      end if        
    else
      fil02.WriteLine date & " " & time & " ERROR reading line at: " & totline01
    end if
  loop
file02.close

end function

1 comment: