原理跟脚本一样,调系统自带 IMAPI2,不用装东西。2-4GB 大概 13 分钟,看到”完成”就是好了,ISO 会生成在文件夹。
$src = 'F:\office\office2024'
$dst = 'F:\office\office2024.iso'
if (Test-Path $dst) { Remove-Item $dst -Force }
Add-Type -TypeDefinition @"
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
public static class IsoW {
public static void Write(object comStream, string path) {
IStream s = (IStream)comStream;
byte[] buf = new byte[1048576];
using (FileStream fs = File.Create(path)) {
while (true) {
IntPtr pr = Marshal.AllocHGlobal(sizeof(int));
try {
s.Read(buf, buf.Length, pr);
int got = Marshal.ReadInt32(pr);
if (got <= 0) break;
fs.Write(buf, 0, got);
} finally { Marshal.FreeHGlobal(pr); }
}
}
}
}
"@
$img = New-Object -ComObject IMAPI2FS.MsftFileSystemImage
$img.VolumeName = 'OFFICE2024'
$img.FileSystemsToCreate = 4
$img.FreeMediaBlocks = 10000000
$img.Root.AddTree($src, $false)
$res = $img.CreateResultImage()
[IsoW]::Write($res.ImageStream, $dst)
"完成: $dst ({0:N1} MB)" -f ((Get-Item $dst).Length/1MB)
原创文章,作者:开心电脑网,如若转载,请注明出处。