[Main]
Title=PreConfig
Type=script
Level=1
Description=Mounting source, detecting languages and more...
Selected=True
Version=12
Contact=vistape@vistape.net
Date=12.10.2008
Locked=false
Download_Level=0
Author=NightMan
Mandatory=True

[Process]
Echo,"Preparing system..."
If,"%Version%",Smaller,"075",begin
Message,"Winbuilder 075 or higher is needed",Error
Exit,"Winbuilder 075 or higher is needed"
end
DirMake,"%basedir%\Temp"
DirMake,"%basedir%\Temp\%ProjectName%"
DirMake,"%basedir%\Custom"
DirMake,"%basedir%\Custom\%ProjectName%"
DirMake,%BootSRC%
DirMake,%InstallSRC%
DirMake,"%ISODir%"
DirMake,"%TargetDir%"
If,ExistDir,"%WindowsDir%\SysWOW64",Set,%SysType%,"amd64"
If,NotExistDir,"%WindowsDir%\SysWOW64",Set,%SysType%,"x86"
run,%ScriptFile%,AutoDetectWimTool
run,%ScriptFile%,Find-Vista
If,%VISTACD%,Equal,"OK",run,%ScriptFile%,MountVista
If,%VISTACD%,NotEqual,"OK",run,%ScriptFile%,Find-WAIK
#####################
#Detecting source type
If,ExistDir,"%BootSRC%\Windows\SysWOW64",run,%ScriptFile%,WrongBootWim
If,ExistDir,"%InstallSRC%\Windows\SysWOW64",run,%ScriptFile%,WrongInstallWim
#####################
#Detecting source language
run,%ScriptFile%,DetectLang
#####################
#Save settings
run,%ScriptFile%,SaveSettings
#####################
#Detecting SP
#SP1
If,ExistDir,"%BootSRC%\Windows\System32\DriverStore\FileRepository\megasr.inf_707e247f",IniWrite,%VistaInfo%,"VistaInfo","SourceSPLevel","1"
#SP0
If,NotExistDir,"%BootSRC%\Windows\System32\DriverStore\FileRepository\megasr.inf_707e247f",IniWrite,%VistaInfo%,"VistaInfo","SourceSPLevel","0"
#####################
#Checking mount
If,NotExistFile,"%BootSRC%\Windows\regedit.exe",Message,"Error with mounting source!"
If,NotExistFile,"%BootSRC%\Windows\regedit.exe",Exit,"Error with mounting source!"

[WrongBootWim]
If,"%ImageTool%",Equal,"WimUtil",ShellExecute,Hide,"#$q%tools%\wimutil.exe#$q","unmount #$q%BootSRC%#$q"
If,"%ImageTool%",Equal,"ImageX",ShellExecute,Hide,"#$q%IMAGEX%#$q","/unmount #$q%BootSRC%#$q"
Message,"x64 source not support yet#$c please choose different boot.wim container!"
Halt,"x64 source not support yet#$c please choose different boot.wim container!"

[WrongInstallWim]
If,"%ImageTool%",Equal,"WimUtil",ShellExecute,Hide,"#$q%tools%\wimutil.exe#$q","unmount #$q%InstallSRC%#$q"
If,"%ImageTool%",Equal,"ImageX",ShellExecute,Hide,"#$q%IMAGEX%#$q","/unmount #$q%InstallSRC%#$q"
Message,"x64 source not support yet#$c please choose different install.wim container!"
Halt,"x64 source not support yet#$c please choose different install.wim container!"

[AutoDetectWimTool]
run,%ScriptFile%,AutoFindImagex
If,"%ImageTool%",NotEqual,"ImageX",run,%ScriptFile%,Find-WimUtil
If,"%ImageTool%",NotEqual,"ImageX",Set,"%ImageTool%","WimUtil"

[AutoFindImagex]
Echo,"Detecting #$qimagex.exe#$q..."
If,ExistFile,"%pFileBox1%\Tools\%SysType%\imagex.exe",Set,"%IMAGEX%","%pFileBox1%\Tools\%SysType%\imagex.exe"
If,ExistFile,"%pFileBox1%\Tools\%SysType%\imagex.exe",Set,"%ImageTool%","ImageX"
If,ExistFile,"%pFileBox1%\Tools\%SysType%\imagex.exe",Set,"%WAIKDir%","%pFileBox1%"
If,ExistFile,"%Tools%\imagex.exe",Set,"%IMAGEX%","%Tools%\imagex.exe"
If,ExistFile,"%Tools%\imagex.exe",Set,"%ImageTool%","ImageX"
If,ExistFile,"%ProgramFilesDir%\Windows#$sAIK\Tools\%SysType%\imagex.exe",Set,"%IMAGEX%","%ProgramFilesDir%\Windows#$sAIK\Tools\%SysType%\imagex.exe"
If,ExistFile,"%ProgramFilesDir%\Windows#$sAIK\Tools\%SysType%\imagex.exe",Set,"%ImageTool%","ImageX"
If,ExistFile,"%ProgramFilesDir%\Windows#$sAIK\Tools\%SysType%\imagex.exe",Set,"%WAIKDir%","%ProgramFilesDir%\Windows#$sAIK"
If,"%SysType%",Equal,"amd64",run,%ScriptFile%,Win64Check

[Win64Check]
If,"%ImageTool%",NotEqual,"ImageX",Message,"Warning! Windows x64 detected#$c please install Microsoft WAIK#$c other WIM tools will not be work on your system!"
If,"%ImageTool%",NotEqual,"ImageX",Halt,"Please install WAIK. Exiting..."

[SaveSettings]
Echo,"Saving settings..."
If,NotExistFile,%VistaInfo%,FileCreateBlank,%VistaInfo%
IniAddSection,%VistaInfo%,"VistaInfo"
IniWrite,%VistaInfo%,"VistaInfo","WimTools","%ImageTool%"
If,"%ImageTool%",Equal,"ImageX",IniWrite,%VistaInfo%,"VistaInfo","imagex","%IMAGEX%"
IniWrite,%VistaInfo%,"VistaInfo","Language","%DistLang%"
If,%VISTACD%,Equal,"OK",IniWrite,%VistaInfo%,"VistaInfo","SourceType","VistaCD"
If,%WAIK%,Equal,"OK",IniWrite,%VistaInfo%,"VistaInfo","SourceType","WAIK"
IniWrite,%VistaInfo%,"VistaInfo","SourceDir","%SDIR%"
If,%VISTACD%,Equal,"OK",IniWrite,%VistaInfo%,"VistaInfo","SystemFiles","%InstallSRC%"
If,%WAIK%,Equal,"OK",IniWrite,%VistaInfo%,"VistaInfo","SystemFiles","%BootSRC%"
IniWrite,%VistaInfo%,"VistaInfo","SysType","%SysType%"
If,%VISTACD%,Equal,"OK",IniWrite,%VistaInfo%,"VistaInfo","DllSrc","%InstallSRC%\Windows\System32"
If,%WAIK%,Equal,"OK",IniWrite,%VistaInfo%,"VistaInfo","DllSrc","%WindowsDir%\System32"
IniWrite,%VistaInfo%,"VistaInfo","WAIKDir","%WAIKDir%"
RegRead,"HKLM","SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName","%WinName%"
IniWrite,%VistaInfo%,"VistaInfo","WinName","%WinName%"
RegRead,"HKLM","SOFTWARE\Microsoft\Windows NT\CurrentVersion","BuildLab","%WinVer%"
IniWrite,%VistaInfo%,"VistaInfo","WinName","%WinVer%"

[DetectLang]
Echo,"Detecting source language..."
If,ExistFile,"%BootSRC%\Windows\System32\en-US\bcdedit.exe.mui",Set,"%DistLang%","en-US"
If,ExistFile,"%BootSRC%\Windows\System32\ar-SA\bcdedit.exe.mui",Set,"%DistLang%","ar-SA"
If,ExistFile,"%BootSRC%\Windows\System32\bg-BG\bcdedit.exe.mui",Set,"%DistLang%","bg-BG"
If,ExistFile,"%BootSRC%\Windows\System32\cs-CZ\bcdedit.exe.mui",Set,"%DistLang%","cs-CZ"
If,ExistFile,"%BootSRC%\Windows\System32\da-DK\bcdedit.exe.mui",Set,"%DistLang%","da-DK"
If,ExistFile,"%BootSRC%\Windows\System32\de-DE\bcdedit.exe.mui",Set,"%DistLang%","de-DE"
If,ExistFile,"%BootSRC%\Windows\System32\el-GR\bcdedit.exe.mui",Set,"%DistLang%","el-GR"
If,ExistFile,"%BootSRC%\Windows\System32\es-ES\bcdedit.exe.mui",Set,"%DistLang%","es-ES"
If,ExistFile,"%BootSRC%\Windows\System32\et-EE\bcdedit.exe.mui",Set,"%DistLang%","et-EE"
If,ExistFile,"%BootSRC%\Windows\System32\fi-FI\bcdedit.exe.mui",Set,"%DistLang%","fi-FI"
If,ExistFile,"%BootSRC%\Windows\System32\fr-FR\bcdedit.exe.mui",Set,"%DistLang%","fr-FR"
If,ExistFile,"%BootSRC%\Windows\System32\he-IL\bcdedit.exe.mui",Set,"%DistLang%","he-IL"
If,ExistFile,"%BootSRC%\Windows\System32\hr-HR\bcdedit.exe.mui",Set,"%DistLang%","hr-HR"
If,ExistFile,"%BootSRC%\Windows\System32\hu-HU\bcdedit.exe.mui",Set,"%DistLang%","hu-HU"
If,ExistFile,"%BootSRC%\Windows\System32\it-IT\bcdedit.exe.mui",Set,"%DistLang%","it-IT"
If,ExistFile,"%BootSRC%\Windows\System32\ja-JP\bcdedit.exe.mui",Set,"%DistLang%","ja-JP"
If,ExistFile,"%BootSRC%\Windows\System32\ko-KR\bcdedit.exe.mui",Set,"%DistLang%","ko-KR"
If,ExistFile,"%BootSRC%\Windows\System32\lt-LT\bcdedit.exe.mui",Set,"%DistLang%","lt-LT"
If,ExistFile,"%BootSRC%\Windows\System32\lv-LV\bcdedit.exe.mui",Set,"%DistLang%","lv-LV"
If,ExistFile,"%BootSRC%\Windows\System32\nb-NO\bcdedit.exe.mui",Set,"%DistLang%","nb-NO"
If,ExistFile,"%BootSRC%\Windows\System32\nl-NL\bcdedit.exe.mui",Set,"%DistLang%","nl-NL"
If,ExistFile,"%BootSRC%\Windows\System32\pl-PL\bcdedit.exe.mui",Set,"%DistLang%","pl-PL"
If,ExistFile,"%BootSRC%\Windows\System32\pt-BR\bcdedit.exe.mui",Set,"%DistLang%","pt-BR"
If,ExistFile,"%BootSRC%\Windows\System32\pt-PT\bcdedit.exe.mui",Set,"%DistLang%","pt-PT"
If,ExistFile,"%BootSRC%\Windows\System32\ro-RO\bcdedit.exe.mui",Set,"%DistLang%","ro-RO"
If,ExistFile,"%BootSRC%\Windows\System32\ru-RU\bcdedit.exe.mui",Set,"%DistLang%","ru-RU"
If,ExistFile,"%BootSRC%\Windows\System32\sk-SK\bcdedit.exe.mui",Set,"%DistLang%","sk-SK"
If,ExistFile,"%BootSRC%\Windows\System32\sl-SI\bcdedit.exe.mui",Set,"%DistLang%","sl-SI"
If,ExistFile,"%BootSRC%\Windows\System32\sr-Latn-CS\bcdedit.exe.mui",Set,"%DistLang%","sr-Latn-CS"
If,ExistFile,"%BootSRC%\Windows\System32\sv-SE\bcdedit.exe.mui",Set,"%DistLang%","sv-SE"
If,ExistFile,"%BootSRC%\Windows\System32\th-TH\bcdedit.exe.mui",Set,"%DistLang%","th-TH"
If,ExistFile,"%BootSRC%\Windows\System32\tr-TR\bcdedit.exe.mui",Set,"%DistLang%","tr-TR"
If,ExistFile,"%BootSRC%\Windows\System32\uk-UA\bcdedit.exe.mui",Set,"%DistLang%","uk-UA"
If,ExistFile,"%BootSRC%\Windows\System32\zh-CN\bcdedit.exe.mui",Set,"%DistLang%","zh-CN"
If,ExistFile,"%BootSRC%\Windows\System32\zh-HK\bcdedit.exe.mui",Set,"%DistLang%","zh-HK"
If,ExistFile,"%BootSRC%\Windows\System32\zh-TW\bcdedit.exe.mui",Set,"%DistLang%","zh-TW"
Echo,"Detected %DistLang% language"

[MountVista]
If,"%ImageTool%",Equal,"ImageX",run,%ScriptFile%,MountVista-imagex
If,"%ImageTool%",Equal,"WimUtil",run,%ScriptFile%,MountVista-wimutil

[MountVista-imagex]
Echo,"Mounting Windows Vista files with imagex.exe..."
ShellExecute,Hide,"#$q%IMAGEX%#$q","/mount #$q%SDIR%\sources\boot.wim#$q %pScrollBox1% #$q%BootSRC%#$q"
ShellExecute,Hide,"#$q%IMAGEX%#$q","/mount #$q%SDIR%\sources\install.wim#$q %pScrollBox2% #$q%InstallSRC%#$q"

[MountVista-wimutil]
Echo,"Mounting Windows Vista files with wimutil.exe..."
ShellExecute,Hide,"#$q%tools%\wimutil.exe#$q","mount #$q%SDIR%\sources\boot.wim#$q #$q%BootSRC%#$q /%pScrollBox1%"
ShellExecute,Hide,"#$q%tools%\wimutil.exe#$q","mount #$q%SDIR%\sources\install.wim#$q #$q%InstallSRC%#$q /%pScrollBox2%"

[MountWAIK]
If,"%ImageTool%",Equal,"ImageX",run,%ScriptFile%,MountWAIK-imagex
If,"%ImageTool%",Equal,"WimUtil",run,%ScriptFile%,MountWAIK-wimutil

[MountWAIK-imagex]
Echo,"Mounting WAIK files with imagex.exe..."
#ShellExecute,Hide,"#$q%IMAGEX%#$q","/mount #$q%SDIR%\winpe.wim#$q %pScrollBox1% #$q%BootSRC%#$q"
ShellExecute,Hide,"#$q%IMAGEX%#$q","/mount #$q%SDIR%\winpe.wim#$q 1 #$q%BootSRC%#$q"

[MountWAIK-wimutil]
Echo,"Mounting WAIK files with wimutil.exe..."
#ShellExecute,Hide,"#$q%tools%\wimutil.exe#$q","mount #$q%SDIR%\winpe.wim#$q #$q%BootSRC%#$q /%pScrollBox1%"
ShellExecute,Hide,"#$q%tools%\wimutil.exe#$q","mount #$q%SDIR%\winpe.wim#$q #$q%BootSRC%#$q /1"

[SourceNotFound]
Message,"Can not detect source type, you must select folder with WAIK or Windows Vista files...#$x#$xExiting..."
Halt,"Exiting.."

[Find-WAIK]
Echo,"Detecting WAIK..."
If,ExistFile,"%ProgramFilesDir%\Windows#$sAIK\Tools\PETools\x86\winpe.wim",Set,"%SDIR%","%ProgramFilesDir%\Windows#$sAIK\Tools\PETools\x86"
If,ExistFile,"%SourceDir%\Windows#$sAIK\Tools\PETools\x86\winpe.wim",Set,"%SDIR%","%SourceDir%\Windows#$sAIK\Tools\PETools\x86"
If,ExistFile,"%SourceDir%\Tools\PETools\x86\winpe.wim",Set,"%SDIR%","%SourceDir%\Tools\PETools\x86"
If,ExistFile,"%SourceDir%\winpe.wim",Set,"%SDIR%","%SourceDir%"
If,ExistFile,"%ProgramFilesDir%\Windows#$sAIK\Tools\PETools\x86\winpe.wim",Set,%WAIK%,"OK"
If,ExistFile,"%SourceDir%\Windows#$sAIK\Tools\PETools\x86\winpe.wim",Set,%WAIK%,"OK"
If,ExistFile,"%SourceDir%\Tools\PETools\x86\winpe.wim",Set,%WAIK%,"OK"
If,ExistFile,"%SourceDir%\winpe.wim",Set,%WAIK%,"OK"
If,"%WAIK%",Equal,"OK",Echo,"WAIK found [%SDIR%]"
If,"%WAIK%",Equal,"OK",run,%ScriptFile%,MountWAIK
If,"%WAIK%",NotEqual,"OK",run,%ScriptFile%,SourceNotFound

[Find-Vista]
Echo,"Detecting Microsoft Windows Vista DVD..."
If,ExistFile,"%SourceDir%\sources\boot.wim",Set,%SDIR%,"%SourceDir%"
If,ExistFile,"%SourceDir%\sources\boot.wim",Set,%VISTACD%,"OK"
If,ExistFile,"%SourceDir%\sources\boot.wim",Echo,"Vista DVD found [%SDIR%]"

[Find-WimUtil]
If,"%SysType%",Equal,"amd64",Echo,"WimUtil not compatible with Windows x64. #$x#$xExiting..."
If,"%SysType%",Equal,"amd64",Message,"WimUtil not compatible with Windows x64. #$x#$xExiting..."
If,"%SysType%",Equal,"amd64",exit,"Exiting.."
Echo,"Detecting WimUtil..."
#TODO
#pb
#If,"%SysType%",NotEqual,"amd64",RegRead,"HKLM","SYSTEM\CurrentControlSet\Services\FltMgr","DisplayName","%RegName%"
#If,"%SysType%",NotEqual,"amd64",If,"%RegName%",NotEqual,"FltMgr",run,%ScriptFile%,FltMgr
#RegRead,"HKLM","SYSTEM\CurrentControlSet\Services\FltMgr","DisplayName","%RegName%"
#If,"%RegName%",NotEqual,"FltMgr",run,%ScriptFile%,FltMgr
#
#RegRead,"HKLM","SYSTEM\CurrentControlSet\Services\WimFltr","DisplayName","%RegName%"
#If,"%RegName%",NotEqual,"WimFltr",run,%ScriptFile%,WinUtil
RegName=WimFltr
If,notExistFile,"%Tools%\wimutil.exe",Halt,"Something wrong with WimUtils..."

[process-NoImagexFound]
Message,"Can not detect #$qimagex.exe#$q, building can not be processed. #$x#$xExiting..."
exit,"Exiting.."

[FltMgr]
Message,"Microsoft Filesystem Filter Manager (fltmgr.sys) not found, please install latest SP. #$x#$xExiting..."
Halt,"Exiting.."

[WinUtil]
ExtractFile,%ScriptFile%,WIM,"WimUtil.exe","%Tools%"
ShellExecute,Hide,#$q%Tools%\WimUtil.exe#$q,"install"

[Interface]
pFileBox1=,1,13,6,59,202,28,dir
pTextLabel1="Folder with installed WAIK, if you have it.",1,1,212,64,209,18,8,Normal
pTextLabel2="Preconfiguration script, detect WIM tool, source type and locale.",1,1,6,22,379,18,8,Bold
pScrollBox1=2,1,4,111,138,55,21,1,2,3,4,5,6,7,8,9,10
pScrollBox2=1,1,4,111,167,56,21,1,2,3,4,5,6,7,8,9,10
pTextLabel3="boot.wim container",1,1,10,140,109,18,8,Normal
pTextLabel4="install.wim container",1,1,10,169,104,18,8,Normal
pTextLabel5="Windows Vista source settings:",1,1,8,115,230,18,8,Bold

[InterfaceEncoded]

[AuthorEncoded]
VistaPE-11-Small.gif=1Kb,1Kb
Logo=VistaPE-11-Small.gif

[EncodedFile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