How to create a simple plugin?

Some short advice: To save yourself trouble and unnecessary work, check the PluginRepository and other plugin pages to see if there is already a plugin for your program or a tool that does the same job. If you don't find what you need, go to the forum and search for you program, it might be under construction or even not working in BartPE. Also, as it runs from a read-only medium, you can only write to Ramdisk, so many programs have to be adapted to write configuration files there. There are many small tools that do a great job and have been adapted to do this already. I don't want to scare you away from writing your own plugins (it's actually quite addictive), just don't go and say "I want MS Office 2003 on it" and be disappointed if it won't work. But now to the howto.

1. Install your application on a Windows XP SP1 (or higher) box. You might want to run Sysinternals filemon and regmon during the installation to determine the files and registry entries added to your system.

2. Create a directory (e.g. MyTool) for the application in your PEbuilder\plugins directory. Create a subdirectory named files.

3. From your WinXP Installation directory (i.e. C:\Program Files\MyTool), copy all files and subdirectories to the PEbuilder\plugins\MyTool\files directory.

4. Get a tool to check file dependencies, e.g. Dependency Walker . Run the executionable through it to determine the needed dlls etc.

5. Check which files from 4. are on you Windows XP SP1/SP2 CD. Add the remaining to the files directory.

6. Create an empty ASCII text file (e.g. using notepad) and save it to PEbuilder\plugins\MyTool\MyTool.inf. It is a good idea to take an .inf file from a plugin already shipped with pebuilder (e.g. adaware.inf) and modify it. It has to look similar to this:

-------------------------------------------------------

; MyTool.inf
; PE Builder v3 plug-in INF file for MyTool
; Created by Me

[Version]
Signature= "$Windows NT$"

[PEBuilder]
Name="MyTool"
Enable=1
Help="mytool.htm"

[WinntDirectories]
a="Programs\mytool",2
b="Programs\mytool\subdir",2

[SourceDisksFiles]
files\mytool.exe=a,,1
files\mytool.ini=b,,1

etc.

[Append]
nu2menu.xml, MyTool_nu2menu.xml

-------------------------------------------------------------

As you see, the .inf file is divided in different section. The header is just information to know which tool this file refers to and who wrote the plugin.

The section [Version] must not be changed.

In the section [PEBuilder] you just enter the name of your program, select if you want it enabled by default (Enable=1) or not (Enable=0) and you state the name of the help file you'll write to tell others how to use your plugin.

The section [WinntDirectories] tells PEBuilder which directories to create for your program, and where. You need an entry here for the program itself (it usually goes in the folder Programs\MyTool) and each subdirectory. The variables (a-z) in front are needed for the next section. The number 2 after the comma tells PEBuilder to create the directory on the root of the CD, not in folder i386. You can combine it with the number one (just add them up making 3) which tells PEBuilder to create the folder even if it stays empty.

The section [SourceDisksFiles] tells PEBuilder from where to take the files belonging to your program and where to put them. In this example, the file mytool.exe is taken from the directory files and put in the directory a from the previous section. There are also numeric directory codes which represent system directories, e.g. system32 is represented by the number 2. For a complete list of the directory codes, see here. In between the two commas in our example, you can state an alternative filename you want the file to have on the CD, in case a different file with the same name is already present. The plugin for ERD Commander uses this to add it's own version of explorer.exe without overwriting the original file. The number 1 at the end tells PEBuilder to check if the file exists in the given folder, and to give an error message if not. Wildcards can be used here, like files\*.dll=2,,1 or files\*.*=a. In case you want every file to be listed in the .inf file, using dir /b > files.txt might save you a lot of work.

If you want to add the whole files to the same folder, you can use a section (not in the above example) called [SourceDisksFolders] and add an entry similar to this: files=a,,1.

There are some more possible sections for an .inf file allowing you to add and delete registry entries in BartPE, these will be explained in another howto. If you make a simple plugin without needing registry entries, you're nearly done now.

The section [Append] tells PEBuilder to append the file MyTool_nu2menu.xml, which you will create as a last step, to nu2menu, the BartPE equivalent to the Windows Start Menu.

Save your file to PEBuilder\plugins\MyTool\MyTool.inf.

7. Have a look at the adaware plugin folder of pebuilder again. Open the adaware_nu2menu.xml with an editor (no matter if text or html editor) and simply adjust the paths in there for your own plugin. Save it to PEBuilder\plugins\MyTool\MyTool_nu2menu.xml. It should now look something like this:

---------------------------------------------------------

<!-- Nu2Menu entry for MyTool -->
<NU2MENU>
<MENU ID="Programs">
<MITEM TYPE="ITEM" DISABLED="@Not(@FileExists(@GetProgramDrive()\Programs\mytool\MyTool.exe))" CMD="RUN" FUNC="@GetProgramDrive()\Programs\mytool\MyTool.exe">DiskEditor</MITEM>
</MENU>
</NU2MENU>

----------------------------------------------------------

8. Create a html file with a description of how to install the plugin, the homepage of your program MyTool, name of the plugin author, version number of your plugin etc. You might want to model your page to help files of already existing plugins. Save it to PEBuilder\plugins\MyTool.htm.

9. Build BartPE with your plugin, try it out and look for errors, then share it on the forum. The usual way to do this is either to put the code of the files in your posting, or put all the files from Pebuilder\plugins\Mytool in a .cab file and offer it for download. Do not include the files folder or the program itself, you might get in trouble due to copyright. Also, it keeps the download small.

 

That's it, have fun trying.