We've already discussed previously the introduction of a new API to be used inside scripts.
Over the last months it became more visible that a more universal and project independent way to create scripts that can add programs inside our projects needs to be used.
So far we've been creating scripts that were written specifically for nativeEx or LiveXP or BartPECore, but why rewrite a script since most tasks are simply repeated across projects and need to make different scripts that add the same program?
To solve this matter a simple set of functions can be used and made available to all scripts across all currently developed projects and the future ones to come. This way your application scripts will still work even when you use another project.
Before, a script would need to adapt to work under a specific project
Now, projects can adapt to work with these scripts and we get an very big ammount of possible scripts to use inside any project that adds support for this method.
Please note - this doesn't mean that projects need to work exclusively with this API method - just need to add a few variables that are recognized by these scripts. All scripts that were specifically written to work with a specific will still work as well as before..
I am posting the changes that should be made for this method to work with LiveXP, NativeEx and NativePE projects.
It should soon be adapted for other projects and the concept remains the same - we use variables instead of fixed names and this way make everything work in a more "universal" way which is valid for most common cases when we want to add a program inside a project.
Add on script.project:
[variables]%api%=%projectdir%\Basic\Build\api.scriptAdd_Shortcut=Run,%api%,AddShortcutRequire_File=run,%api%,expand_fileUnpack=Run,%api%,depack%source_win%=%SourceDir%\I386%target_win%=%targetDir%\I386%source_sys%=%SourceDir%\I386%target_sys%=%TargetDir%\I386\System32%HIVE_HKLM%=%targetDir%\I386\System32\setupreg.hiv%HIVE_HKCU%=%TargetDir%\i386\System32\Config\default%HIVE_HKU%=%targetDir%\I386\System32\Config\software%HIVE_BASE%=HKLM%reg_temp%=wb-hive%reg%\=%reg_temp%\hive_load=run,%api%,reg_hiveloadhive_unload=run,%api%,reg_hiveunloadreg_add=RegWrite,"%HIVE_BASE%"associate_file=run,%api%,do_associateThis api.script can be placed anywhere you wish but we've defined %api% with the value "%projectdir%\Basic\Build\api.script" inside script.project so it should be placed by default inside the Basic\Build folder.
[main]Title=apiDescription=This script contains a set of magic functions that you can use inside your script to make some tasks easier like creating shortcuts and extracting files.Selected=noneLevel=1Credits=To the whole community of developers, beta testers and active members which make these developments fun and interesting.Date=2007-JUL-25Version=2Contact=http://www.boot-land.net/forums/Common-API-for-projects-t2100.htmlDownload_Level=0Author=Boot Land Community[expand_file]If,NotExistFile,%target_sys%\#1,CopyOrExpand,"%source_sys%\#1","%target_sys%"[AddShortcut]echo,""echo,"API - Creating a new shortcut for %programTitle%.. [%programFolder%\%programExe%]"If,#1,Equal,,Set,"%shortcut_type%","SM"If,#1,Equal,Desktop,Set,"%shortcut_type%","DE"If,#1,Equal,StartMenu,Set,"%shortcut_type%","SM"If,#1,Equal,QuickLaunch,Set,"%shortcut_type%","QL"If,#1,Equal,AutoStart,Set,"%shortcut_type%","AU"If,#2,Equal,,StrFormat,filename,%Scriptdir%,#2Run,%BuildModelScript%,Add-Shortcut,"%shortcut_type%\#2","#$pProgramFiles#$p\%programFolder%\%programExe%","%ProgramTitle%","-SW:#$pProgramFiles#$p\%programFolder%"[depack]echo,"API - Unpacking files and settings.."Set,%folder_name%,#1If,%folder_name%,Equal,,Set,%folder_name%,Foldersystem,refreshvarsIniRead,"%ProjectInfo%","TargetPaths","Program_Files",%WorkDir%DirMake,"%targetDir%\%workDir%"DirMake,"%targetDir%\%workDir%\%ProgramFolder%"echo,"Extracting %ProgramTitle%.."ExtractAllFiles,"%ScriptFile%","%folder_name%","%targetDir%\%workDir%\%ProgramFolder%"[reg_hiveload]/echo,"Loading #1 hive.."Set,"%hive_file%","%HIVE_#1%"System,RefreshVarsecho,"Loading hive from %hive_file%"RegHiveLoad,%reg_temp%,%hive_file%[reg_hiveunload]/echo,"Unloading %reg_temp%"RegHiveUnLoad,%reg_temp%[do_associate]echo,""echo,"API - Associating #1 filetype.."Set,"%my_file_type_label%","#1file"Set,"%my_file_type%","#1"Set,"%my_file_type_action%","#2"Set,"%my_icon_file%","#3"Set,"%my_icon_file_number%","#4"system,refreshvarshive_load,HKUreg_add,0x1,"%reg%\Classes\.%my_file_type%",,"%my_file_type_label%"If,%my_file_type_action%,Equal,,run,%api%,do_associate_action,openIf,%my_file_type_action%,Equal,open,run,%api%,do_associate_with_other_fileIf,%my_file_type_action%,Equal,edit,run,%api%,do_associate_action,editIf,%my_file_type_action%,Equal,icon,run,%api%,do_associate_iconhive_unload,HKU[do_associate_action]If,#1,Equal,open,run,%api%,do_associate_iconIf,%my_file_type_action%,Equal,,Set,"%my_file_type_action%","open"Set,"%my_parameters%","#$q%1#$q"If,#2,NotEqual,,Set,"%my_parameters%","#2"reg_add,0x2,"%reg%\Classes\%my_file_type_label%\shell\%my_file_type_action%\command",,"#$q#$pProgramFiles#$p\%programFolder%\%programExe%#$q#$s%my_parameters%"[do_associate_with_other_file]run,%api%,do_associate_iconSet,%my_parameters%,"#$s#$q%1#$q"If,%my_icon_file_number%,NotEqual,,Set,%my_parameters%,"#$s%my_icon_file_number%"system,refreshvarsreg_add,0x2,"%reg%\Classes\%my_file_type_label%\shell\%my_file_type_action%\command",,"%my_icon_file%%my_parameters%"[do_associate_icon]If,%my_icon_file%,Equal,,Set,"%my_icon_file%","#$q#$pProgramFiles#$p\%programFolder%\%programExe%#$q"system,refreshvarsIf,%my_icon_file_number%,Equal,,reg_add,0x2,"%reg%\Classes\%my_file_type_label%\DefaultIcon",,"%my_icon_file%"If,%my_icon_file_number%,NotEqual,,reg_add,0x2,"%reg%\Classes\%my_file_type_label%\DefaultIcon",,"%my_icon_file%#$c%my_icon_file_number%"[demo usage]; Use these examples to see how these commands can be applied inside your app scriptsAdd_ShortcutAdd_Shortcut,StartMenuAdd_Shortcut,StartMenu,GamesAdd_Shortcut,QuickLaunchAdd_Shortcut,AutoStartAdd_Shortcut,Desktoprequire_file,myLibrary.dllunpackunpack,AnotherFolderhive_load,HKUhive_unload,HKUreg_add,0x1,"%reg%\Classes\filetype","test","1"associate_file,htmlassociate_file,html,open,c:\test.exeassociate_file,html,open,c:\test.exe,/run=%2associate_file,html,editassociate_file,html,icon,c:\test.exeassociate_file,html,icon,%systemroot%\System32\Shell32.dll,-153[history]070513 - api.script was created.070718 - added function "require" (extract/check if system files are available and expand from source if needed- added syntax guide inside script.project from livexp- added %HKLM% and %HKCU% to write registry keys- added %source_win%, %target_win%, %source_sys%, %target_sys%that allow access work folders under most situations (supports both Install CD files or Installed windows dirs)070723 - added support for creating start menu items based on the folder where the script is placed070723 - hive_load and hive_unload commands added to support HKCU,HKU and HKLM070723 - reg_add command added with support for internal and external hive registry writes070723 - association command was also added to bring support to file associations070724 - added support to add association to any other files along with custom parameters and custom icons (like shell32.dll,-153)070724 - unpack was made simpler also extracting from any folder when specifiedThe above settings might seem a bit complicated, but they are also meant as reference for those who maintain our script projects - by default - most .script developers and everyone else who wishes to write a script won't ever need to worry about them and only needs to know which functions can be used inside their scripts.Proper documentation to explain all this still needs to be elaborated, but here is a small set of demonstration commands that show the scope of possible actions
[Process]Echo,"Making new directories.."IniRead,"%ProjectInfo%","TargetStrings","sProgram_Files",%WorkDir%DirMake,%targetDir%\%workDir%\dixml// Add shortcutsIf,%pCheckBox1%,Equal,True,Run,%BuildModelScript%,Add-Shortcut,"DE","#$pSystemDrive#$p\%workDir%\dixml\dixml.exe","DriveImage XML"Run,%BuildModelScript%,Add-Shortcut,"SM\Backup","#$pSystemDrive#$p\%workDir%\dixml\dixml.exe","DriveImage XML"Echo,"Extract files.."ExtractAllFiles,"%ScriptFile%","Folder","%targetDir%\%workDir%\dixml"Expand,"%SourceDir%\I386\APPHELP.DL_","%TargetDir%\i386\system32"Expand,"%SourceDir%\I386\LZ32.DL_","%TargetDir%\i386\system32"Expand,"%SourceDir%\I386\WOW32.DL_","%TargetDir%\i386\system32"Expand,"%SourceDir%\I386\NTVDM.EX_","%TargetDir%\i386\system32"Echo,"Loading registry hive: [%TargetDir%\i386\System32\Config\software]"RegHiveLoad,Tmp_software,%TargetDir%\i386\System32\Config\softwareEcho,"Writing new values on registry hive.."RegWrite,HKLM,0x1,"Tmp_software\Microsoft\Windows NT\CurrentVersion\Fonts","MS Sans Serif 8,10,12,14,18,24 (VGA res)","SSERIFE.FON"RegWrite,HKLM,0x1,"Tmp_software\Microsoft\Windows NT\CurrentVersion\Fonts","MS Serif 8,10,12,14,18,24 (VGA res)","SERIFE.FON"RegWrite,HKLM,0x1,"Tmp_software\Microsoft\Windows NT\CurrentVersion\Fonts","Small Fonts (VGA res)","SMALLE.FON"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{43A8F463-4222-11d2-B641-006097DF5BD4}","","Shell Name Space ListView"RegWrite,HKLM,0x2,"Tmp_software\Classes\CLSID\{43A8F463-4222-11d2-B641-006097DF5BD4}\InProcServer32","","%SystemRoot%\System32\shdocvw.dll"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{43A8F463-4222-11d2-B641-006097DF5BD4}\InProcServer32","ThreadingModel","Apartment"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{603D3800-BD81-11d0-A3A5-00C04FD706EC}","","Background Task Scheduler"RegWrite,HKLM,0x2,"Tmp_software\Classes\CLSID\{603D3800-BD81-11d0-A3A5-00C04FD706EC}\InProcServer32","","%SystemRoot%\System32\browseui.dll"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{603D3800-BD81-11d0-A3A5-00C04FD706EC}\InProcServer32","ThreadingModel","Apartment"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}","","Shell Automation Service"RegWrite,HKLM,0x2,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\InProcServer32","","%SystemRoot%\system32\SHELL32.dll"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\InProcServer32","ThreadingModel","Apartment"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\ProgID","","Shell.Application.1"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\TypeLib","","{50a7e9b0-70ef-11d1-b75a-00a0c90564fe}"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\Version","","1.1"RegWrite,HKLM,0x1,"Tmp_software\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\VersionIndependentProgID","","Shell.Application"RegWrite,HKLM,0x1,"Tmp_software\Classes\Shell.Application","","Shell Automation Service"RegWrite,HKLM,0x1,"Tmp_software\Classes\Shell.Application\CLSID","","{13709620-C279-11CE-A49E-444553540000}"RegWrite,HKLM,0x1,"Tmp_software\Classes\Shell.Application\CurVer","","Shell.Application.1"RegWrite,HKLM,0x1,"Tmp_software\Classes\Shell.Application.1","","Shell Automation Service"RegWrite,HKLM,0x1,"Tmp_software\Classes\Shell.Application.1\CLSID","","{13709620-C279-11CE-A49E-444553540000}"RegHiveUnLoad,Tmp_softwareAfter
[variables]%ProgramTitle%=DriveImage XML%ProgramEXE%=dixml.exe%ProgramFolder%=DriveImageXML[process]If,%pCheckBox1%,Equal,True,Add_Shortcut,DesktopAdd_Shortcut,StartMenuunpackecho,"Expanding DLLs..."require_file,APPHELP.DLLrequire_file,LZ32.DLLrequire_file,WOW32.DLLrequire_file,NTVDM.EXEhive_load,HKUreg_add,0x1,"%reg%\Microsoft\Windows NT\CurrentVersion\Fonts","MS Sans Serif 8,10,12,14,18,24 (VGA res)","SSERIFE.FON"reg_add,0x1,"%reg%\Microsoft\Windows NT\CurrentVersion\Fonts","MS Serif 8,10,12,14,18,24 (VGA res)","SERIFE.FON"reg_add,0x1,"%reg%\Microsoft\Windows NT\CurrentVersion\Fonts","Small Fonts (VGA res)","SMALLE.FON"reg_add,0x1,"%reg%\Classes\CLSID\{43A8F463-4222-11d2-B641-006097DF5BD4}","","Shell Name Space ListView"reg_add,0x2,"%reg%\Classes\CLSID\{43A8F463-4222-11d2-B641-006097DF5BD4}\InProcServer32","","%SystemRoot%\System32\shdocvw.dll"reg_add,0x1,"%reg%\Classes\CLSID\{43A8F463-4222-11d2-B641-006097DF5BD4}\InProcServer32","ThreadingModel","Apartment"reg_add,0x1,"%reg%\Classes\CLSID\{603D3800-BD81-11d0-A3A5-00C04FD706EC}","","Background Task Scheduler"reg_add,0x2,"%reg%\Classes\CLSID\{603D3800-BD81-11d0-A3A5-00C04FD706EC}\InProcServer32","","%SystemRoot%\System32\browseui.dll"reg_add,0x1,"%reg%\Classes\CLSID\{603D3800-BD81-11d0-A3A5-00C04FD706EC}\InProcServer32","ThreadingModel","Apartment"reg_add,0x1,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}","","Shell Automation Service"reg_add,0x2,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\InProcServer32","","%SystemRoot%\system32\SHELL32.dll"reg_add,0x1,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\InProcServer32","ThreadingModel","Apartment"reg_add,0x1,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\ProgID","","Shell.Application.1"reg_add,0x1,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\TypeLib","","{50a7e9b0-70ef-11d1-b75a-00a0c90564fe}"reg_add,0x1,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\Version","","1.1"reg_add,0x1,"%reg%\Classes\CLSID\{13709620-C279-11CE-A49E-444553540000}\VersionIndependentProgID","","Shell.Application"reg_add,0x1,"%reg%\Classes\Shell.Application","","Shell Automation Service"reg_add,0x1,"%reg%\Classes\Shell.Application\CLSID","","{13709620-C279-11CE-A49E-444553540000}"reg_add,0x1,"%reg%\Classes\Shell.Application\CurVer","","Shell.Application.1"reg_add,0x1,"%reg%\Classes\Shell.Application.1","","Shell Automation Service"reg_add,0x1,"%reg%\Classes\Shell.Application.1\CLSID","","{13709620-C279-11CE-A49E-444553540000}"hive_unload,HKUOther app script examplesSmartFTP
[variables]%ProgramTitle%=SmartFTP%ProgramEXE%=SmartFTP.exe%ProgramFolder%=SmartFTP[process]Add_Shortcut,StartMenuunpackrequire_file,APPHELP.DLLrequire_file,ATL.DLLrequire_file,CLBCATQ.DLLrequire_file,COMRES.DLLrequire_file,CREDUI.DLLrequire_file,CRYPT32.DLLrequire_file,CSCDLL.DLLrequire_file,CSCUI.DLLrequire_file,HNETCFG.DLLrequire_file,IMGUTIL.DLLrequire_file,IPHLPAPI.DLLrequire_file,MFC42.DLLrequire_file,MLANG.DLLrequire_file,MSASN1.DLLrequire_file,MSHTML.DLLrequire_file,MSIMTF.DLLrequire_file,MSLS31.DLLrequire_file,MSV1_0.DLLrequire_file,MSWSOCK.DLLrequire_file,MSXML3.DLLrequire_file,NETSHELL.DLLrequire_file,OLEACC.DLLrequire_file,PNGFILT.DLLrequire_file,RASADHLP.DLLrequire_file,RASAPI32.DLLrequire_file,RASMAN.DLLrequire_file,RICHED20.DLLrequire_file,RICHED32.DLLrequire_file,RSAENH.DLLrequire_file,RTUTILS.DLLrequire_file,SHDOCVW.DLLrequire_file,WSHTCPIP.DLL
Reg Shot
[variables]%ProgramTitle%=RegShot%ProgramEXE%=RegShot.exe%ProgramFolder%=RegShot[process]Add_Shortcut,StartMenuunpack
This is not meant to apply for all programs nor is meant to become a "perfect" method - but will make your life simpler when you want to create a new script - there's even a tutorial explaining how this can quickly be done here
Also look inside other scripts already coded with this method under the download section here.
Things may change as we continue our improvements but at least this way you get a good way to write your scripts for a much wider variety of projects - more documentation to follow soon..
How important is this for overall scripting?
Makes things simpler and so much more flexible that we can improve and change our favourite projects and still use all available scripts over the next years to come.