WinPE auto scripts

26.7k views Asked by At

I have just set up a bootable UFD with WinPE 3.0, and I need it to run a couple of scripts automatically on boot.

I was wondering if anyone had any advice on setting up automatic scripts for listing the partitions on the local drive, showing the date of the system, listing the current IP, and capturing an image of the local drive.

If anyone can help that would be great! Thanks.

2

There are 2 answers

0
Zero On

Build your scripts independently and test their functionality prior to placing them inside of your WinPE. Then mount your winPE so you can edit it and place all of your scripts in the winPE

Mounting command:

DISM /Mount-WIM /WimFile:C:..[dir of where your wine is located]\ISO\sources\boot.wim /index:1 /MountDir:mount

Then place your scripts inside of a folder inside your mount folder (which now should have stuff inside of it). Once that completed, you can easily call them by modifying the ..\Windows\System32\startnet.cmd file.

NOTE: DO NOT REMOVE the first line wpeinit. Just add after it: start <scriptname.bat or .vbs>

Save and close.

Keep in mind: if you are doing scripts inside of winPE that handles anything with the NIC, you will need to insert the network drivers into your WinPE. Once your winpe loads, it automatically calls startnet.cmd first.

Some tutorials to do so can be located here.

0
clsturgeon On

I added a batch file to the bootable WinPE image that performs many of these task. It first checks to ensure you are actually running WinPE (and not running the batch file from another OS).

set pVersion=WinPE not found
for /F "usebackq tokens=3" %%A IN (`reg query "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\WinPE" /v "Version" 2^>nul ^| find "Version"`) do (
set pVersion=%%A
)
echo WinPE Version: %pVersion%
IF /I "%pVersion%"=="3.0" GOTO ContinueProc
IF /I "%pVersion%"=="4.0" GOTO ContinueProc
echo *************************************************************************
echo **  ERROR: This restore batch file can only be used in WinPE version   **
echo **  3.0 and 4.0                                                        **
echo *************************************************************************
GOTO ExitInstall

Then I list disk, volume and partition information for disk 0 to the user via...

diskpart /s list.txt

...where list.txt contains...

list disk
list volume
select disk 0
list partition
exit

My batch file would then clean disk 0, format the drive and apply the disk image. I use imagex to capture and apply images. In your case, you stated you wanted to capture a disk image, which you could do to a network drive, another hard drive, a USB hard drive or a UFD.

Eg.

imagex /capture c: y:\mydiskimage.wim "My system disk"

To list the IP you could simply run ipconfig.

If want your batch file to automatically run on boot you could try editing/creating a winpeshl.ini which if added to Windows\System32 folder would launch custom processes.

I ensure I have startnet.cmd, then I list what I want to run. I have added setlw.exe (search online) to ensure my UFD is always drive letter Y. Then you could run your batch file as the last item. In this example I added cmd as well so the user gets a command prompt when all is complete.

[LaunchApps]
%SYSTEMDRIVE%\Windows\system32\startnet.cmd
%SYSTEMDRIVE%\Windows\system32\setlw.exe
Y:\sources\mybatchfile.cmd
%SYSTEMDRIVE%\Windows\system32\cmd.exe

Note: one of the first commands my batch file launches:

chdir /D %~dp0

...to change directory to the location of the batch file.