New
#540
Yah, I'd like to see that script... Wimlib is far better than dism. I did try conveting Winlib to C# but got into a tangle and gave up ( C -> C# is a lot harder than people may think ... also the C compiled dll can't be called with external extern - needs to be re-complied as a C++ dll with the missing header file) - if anyone does manage to port it I would like to know about it...
BTW.. you don't need ADK/oscdimg - I'm using native API's in ESDISO (it's out-dated, I know).. :
I'm sure it can be simplified and ported to PS..... however for this project, calling the third-party stuff will be much easier.Code:using System; using System.Runtime.InteropServices; using IMAPI2FS; using System.IO; namespace ISOBuilder { public class BuildISO { [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_DISPATCH)] Array psaBoot; [DllImport("shlwapi.dll", CharSet = CharSet.Unicode)] static internal extern uint SHCreateStreamOnFile(string pszFile, uint grfMode, out FsiStream ppstm); public void MakeISO(string MBRbootFile, string EFIbootFile,string path, string VolID) { MsftFileSystemImage iso = new MsftFileSystemImage(); psaBoot = Array.CreateInstance(typeof(Object), 2); FsiStream MBRbootStream,EFIbootStream; iso.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); iso.FileSystemsToCreate = FsiFileSystems.FsiFileSystemUDF; iso.VolumeName = VolID; // Need streams for the boot image files UInt32 ret = SHCreateStreamOnFile(MBRbootFile, 0x00, out MBRbootStream); // Create MBR boot BootOptions MBRbootOptions = new BootOptions(); MBRbootOptions.Manufacturer = "Microsoft"; MBRbootOptions.PlatformId = PlatformId.PlatformX86; MBRbootOptions.Emulation = EmulationType.EmulationNone; if (ret == 0) MBRbootOptions.AssignBootImage(MBRbootStream); ///<!-- EFI boot is architecture specific --> ret = SHCreateStreamOnFile(EFIbootFile, 0x00, out EFIbootStream); // Create EFI boot BootOptions EFIbootOptions = new BootOptions(); EFIbootOptions.Manufacturer = "Microsoft"; EFIbootOptions.PlatformId = PlatformId.PlatformEFI; EFIbootOptions.Emulation = EmulationType.EmulationNone; if (ret == 0) EFIbootOptions.AssignBootImage(EFIbootStream); psaBoot.SetValue(MBRbootOptions, 0); psaBoot.SetValue(EFIbootOptions, 1); iso.BootImageOptionsArray = psaBoot; iso.Root.AddTree(path, false); IFileSystemImageResult resultImage = iso.CreateResultImage(); IStream imageStream = resultImage.ImageStream; FsiStream newStream = null; if (imageStream != null) { tagSTATSTG stat; imageStream.Stat(out stat, 0x1); uint res = SHCreateStreamOnFile(path + ".iso", 0x1001, out newStream); if (res == 0 && newStream != null) { _ULARGE_INTEGER inBytes; _ULARGE_INTEGER outBytes; try { imageStream.RemoteCopyTo(newStream, stat.cbSize, out inBytes, out outBytes); } finally { Marshal.FinalReleaseComObject(imageStream); newStream.Commit(0); Marshal.FinalReleaseComObject(newStream); Marshal.FinalReleaseComObject(resultImage); Marshal.FinalReleaseComObject(iso); // if (System.IO.Directory.Exists(path)) System.IO.Directory.Delete(path, true); } } else { Marshal.FinalReleaseComObject(imageStream); Marshal.FinalReleaseComObject(resultImage); Marshal.FinalReleaseComObject(iso); //TODO: Throw exception or do whatever to signal failure here } } else { Marshal.FinalReleaseComObject(resultImage); Marshal.FinalReleaseComObject(iso); //TODO: Throw exception or do whatever to signal failure here } } } }
Edit: a bit late in posting - thanx ffor the script.
Chris Wu's New-IsoFile function only allows for a single boot ISO (i.e. Legacy or EFI) for use to boot a VM from the resulting ISO file. If you choose EFI boot, but use something like Rufus to create a USB stick, you can still boot a physical Legacy BIOS PC with it.
OK, but remember I am not a programmer and have almost no experience with scripting. I just began with wanting to do everything with PowerShell instead of DISM one morning and decided to throw in making the combined Pro and Home ISO. The end result takes forever to run, as it mounts and converts the Home WIM to Pro and then adds it to the Install.wim in the ISO folder. I haven't figured out how to paste the code properly into this forum post (it ends up all in one line for me) so I will attach the text file.
ISOfromESD.txt
That would be much faster to process, but you still need the other 3 Indexes that are in a full ESD file to produce standard Windows 10 install media. Index:1 is the main file and folder structure for the ISO. Indexes 2 & 3 combine to create the full boot.wim and Index:4 is usually either Home or Pro, which is used to create Install.wim in the ISO.A script could be made to take a full Home ESD and then just add a supplied Pro Install.wim to the ISO. That would run much faster as it doesn't have to mount and convert the Home Install.wim to Pro.Code:DISM /Get-WimInfo /WimFile:Install.esd Deployment Image Servicing and Management tool Version: 10.0.14393.0 Details for image : Install.esd Index : 1 Name : Windows Setup Media Description : Windows Setup Media Size : 262,777,817 bytes Index : 2 Name : Microsoft Windows PE (x64) Description : Microsoft Windows PE (x64) Size : 1,633,924,022 bytes Index : 3 Name : Microsoft Windows Setup (x64) Description : Microsoft Windows Setup (x64) Size : 1,786,347,488 bytes Index : 4 Name : Windows 10 Home Description : Windows 10 Home Size : 15,140,872,818 bytes The operation completed successfully.
The Official version 1607 install media includes Windows 10 Pro, Windows 10 Home, Windows 10 Home Single Language and Windows 10 Education combined in one Install.esd.
I believe the UUP to ISO process is missing what is usually Index:3 in the full ESD file that we used to get, which is part of why it ends up not including "Repair your computer" in the end result. But it still works to install Windows.
Which would indicate that those files are already on our system (which they are, considering we have the ability to fix things ourselves directly from boot), and that the current UUP>ISO scripts could, in fact, be amended to add that information back in from an existing Windows 10 Install to make a proper .ISO with repair ability.
Windows Update isn't trying to create a standard Windows install ISO though. It only needs to successfully upgrade Windows to the new build. We are trying to produce bootable Install media instead.
Index:3 is a version of WindowsPE, but it has additional files and folders compared to Index:2. Plus it is normally the same build as what you are upgrading to. Someone would have to analyze exactly what the differences are between Index:2 and Index:3 and figure out how to add in all of the missing folders and files from the new build files which were created by Windows Update in the UUP process.
That is why the working solution is to simply use a prior build ISO and replace install.wim with the new one. You end up with a mix of builds in the ISO, but what it installs is the new build. But when you run Repair your computer, it uses a prior build's WindowsRE.