The GrubUtils utilites can be downloaded from Chenalls site here (this includes wenv, chkpci and other utilities). See the bottom of this page for a recent version (includes 2014 version of chkpci).
There are some interesting utilities that can be called or executed from grub4dos. The documentation is difficult to find and is usually in Chinese. Here are some notes which may be helpful.
When running an external grub4dos batch file or utility executable, you need to copy the file to your boot drive and make sure that the path is specified correctly in the menu.lst file, e.g.
/menuset 0 0 0 0 0 0 10 50 5 29 35
will run the file menuset which must exist on the root of the boot drive. menuset is contained in the grubutils package.
Note: The default command path for grub4dos is the current path (set by the root command) and the /boot/grub folder - it is recommended to place all your utilities in /boot/grub on your boot drive so that grub4dos can find them without needing to set the root or define a full path.
menuset 0 0 0 0 0 0 10 50 5 29 35
will run the file menuset which must exist in the /boot/grub folder or in the current root folder (as shown by the ls command).
The alternative is to path each command - e.g. use /bin/wenv instead of just wenv and place the wenv file at /bin.
Grub4dos Batch files
Max no lines = 2048 in a batch file, Max. no. labels in a batch file =128, file must start with !BAT on first line.
Grub4dos can execute a batch file (usually given a .g4b file extension, but sometime it has a .bat extension or no extension - whereas a grub4dos executable file has a .g4e extension or no extension). The grub4dos batch file must begin with !BAT. The syntax to use in the batch file is similar to that in a menu.lst file but not quite the same. For instance when using two variables together, you must use three % signs in a batch file because any two consecutive % signs will be treated as a single % sign in a batch file:
test.bat file contents:
set a=Fred is a
echo Fred got 100%% in his test!
in a grub4dos commandline shell, type /test.bat
Fred is a GENIOUS!
Fred got 100% in his test!
Note that in a batch file we cannot use %a%%b% - we must add an extra % symbol and use %a%%%b%, but in a menu.lst file, echo %a%%b% will work and you don't need the extra % sign!
If want to add a SPACE before a value using set then use double-quotes:
set "C= fred"
or use double-quotes if it is possible that a variable's value (A in this case) might contain leading spaces (in batch file %%=% so we must use three % signs - %A%%%B%):
tip: If you place all utility and batch files in the /boot/grub folder then grub4dos will find them without needing to specify a path.
tip: If you use debug 3 then you can single step a batch file (on later versions of grub4dos use debug <batchfile> <args> )
Also, if you call a grub4dos utility a lot in a batch file (for instance, in a loop or subroutine), then load it into memory first using the command insmod - e.g.
wenv calc bs=%bs%-%bc2b%
will load wenv into memory so that whenever it is called later (with no path specified) it will run from memory instead of being loaded from the disk each time. Thus using insmod at the start of your batch file to load any utilities into memory will greatly improve the speed of execution! Insmod can also be called from within a menu.lst file and this will increase the speed of execution of grub4dos menus if you call a grub4dos utility within the menu.lst file, as well as any batch files you call afterwards. Use delmod <filename) to unload a file or :
::echo Checking if this batch file is loaded into memory - if not load it for faster execution
delmod -l %~nx0 || insmod %0
#Note: can only use filenames up to 11 characters (including the dot - i.e. up to 8.2 not 8.3) with insmod.
You can also call internal Function calls in a batch file using call Fn.x where x is a number and can be followed by one or more parameters - e.g.:
call Fn.0 0 "Hello" - will print Hello to the console
Here is a batch file to get lines from a text file, one at a time (redirecting bold blue lines will give a perfect copy of the file):
Suppose we release a bootable CD or USB drive which has software on it that should be regularly updated. We want to warn the user when it is about to expire or if it has expired. We can use a grub4dos batch file to do this and call it from a menu.lst file like this:
# Example below: Released on 2102-12-03 Expires in 30 days
/checkdate.g4b 2012 12 3 30
# Example1 without text displayed: /checkdate.g4b 2012 12 3 30 SILENT
# Example2 without text displayed: /checkdate.g4b 2012 12 3 30 > nul
if NOT "%CHECKDATE%"=="OK" reboot
This will show the following text when the grub4dos menu runs...
CheckDate: Release Date 2012-12-31 (Today is 2012-12-31)
CheckDate: This version is good for 30 days from release
CheckDate: This version expires in 29 day(s)
CheckDate: Release Date 2012-12-3 (Today is 2012-12-31)
CheckDate: This version is good for 30 days from release
CheckDate: WARNING: This is older than 30 days!
The checkdate.g4b file can be found at the bottom of this page or click here. If you add the word SILENT to the call parameters then the user will have no idea why it no longer displays a nice menu and just keeps rebooting!
Note: If you are burning this to a CD or DVD, use an 8.3 filename like chkdate.g4b as checkdate.g4b is too long a name!
If you wish to 'encrypt' your menu.lst file so that it is not just a plain text file, use 7Zip to compress the menu.lst file to GZip format (menu.lst.gz) and then rename the file to menu.lst.
grub4dos will still run the compressed menu.lst file just fine but if anyone tries to read the file using a text editor they will find it hard to understand!
Set the System Date
Using the grub4dos Function 53 we can set the Real Time Clock date. The Date.g4b grub4dos batch file can be run to set the date - this might be useful for expiry date sensitive DOS utilities that check the date of the system.
run the batchfile from your menu.lst like this
# set date of system to Jan 30th 2001
# OR ...
# Prompt user to set a date
Note that this will permanently change the date of the system Real Time Clock until you set back the correct time.
grub4dos variables and setlocal/endlocal
Currently there is a maximum limit of 60 variables and each can be up to 512 bytes each.
The batch file VarsLeft.g4b will tell you how many variables remain out of the 60 allowed. It is quite easy to run out if you are not careful!
If you reset them (e.g. set A= will remove the variable A from the environment) then you will free up a 'slot for another variable'.
You can use setlocal to make a copy of the current environment (e.g. variables, root path, current filespec, etc.).
When the endlocal command is run these values are restored and any variables set during the setlocal portion are lost (a copy of the current environment is made when you use setlocal and that copy is restored when you use endlocal).