C# WIMMountImageHandle导致错误\u无效\u句柄
我正在写一个程序 最简单的例子:C# WIMMountImageHandle导致错误\u无效\u句柄,c#,.net,api,C#,.net,Api,我正在写一个程序 最简单的例子: static void Test() { UIntPtr creationResult = UIntPtr.Zero; IntPtr WIMHandle = WIM.WIMCreateFile(@"D:\ISOCpy\install.wim", (uint)WIM.CreateFileAccess.Mount, (uint)WIM.CreateFileMode.OpenExisting, 0, 0, out cre
static void Test()
{
UIntPtr creationResult = UIntPtr.Zero;
IntPtr WIMHandle = WIM.WIMCreateFile(@"D:\ISOCpy\install.wim", (uint)WIM.CreateFileAccess.Mount, (uint)WIM.CreateFileMode.OpenExisting, 0, 0, out creationResult);
if (WIMHandle == IntPtr.Zero)
{
Console.WriteLine("Could not open WIM File. LastError: " + Marshal.GetLastWin32Error() + " / 0x" + Marshal.GetLastWin32Error().ToString("x"));
return;
}
try
{
// Set TMP Path
if (!WIM.WIMSetTemporaryPath(WIMHandle, @"D:\ISOCpy\y"))
{
// handle will be closed in destructor
Console.WriteLine("Could not set WIM temp path. LastError: " + Marshal.GetLastWin32Error() + " / 0x" + Marshal.GetLastWin32Error().ToString("x"));
return;
}
int imgnums = WIM.WIMGetImageCount(WIMHandle);
if (imgnums <= 0)
{
// handle will be closed in destructor
Console.WriteLine("Could not get number of WIMimages. Return: " + imgnums + "; LastError: " + Marshal.GetLastWin32Error() + " / 0x" + Marshal.GetLastWin32Error().ToString("x"));
return;
}
for (uint mountindex = 1; mountindex <= imgnums; mountindex++)
{
String mountpath = @"D:\ISOCpy\z_" + mountindex;
Directory.CreateDirectory(mountpath);
IntPtr ImgHandle = WIM.WIMLoadImage(WIMHandle, mountindex);
if (ImgHandle == IntPtr.Zero)
{
int rc = Marshal.GetLastWin32Error();
Utils.DeleteDir(mountpath);
Console.WriteLine("Could not WIMLoadImage. Image: " + mountindex + "; LastError: " + rc + " / 0x" + rc.ToString("x"));
return;
}
if (!WIM.WIMMountImageHandle(ImgHandle, mountpath, 0))
{
int rc = Marshal.GetLastWin32Error();
Utils.DeleteDir(mountpath);
Console.WriteLine("Could not WIMMountImageHandle. Image: " + mountindex + "; LastError: " + rc + " / 0x" + rc.ToString("x"));
return;
}
}
}
catch (Exception e)
{
Console.WriteLine("" + e);
}
finally
{
//WIM.WIMCloseHandle(WIMHandle); TODO
}
}
static void Test()
{
uintpttr creationResult=uintpttr.Zero;
IntPtr WIMHandle=WIM.WIMCreateFile(@“D:\isopy\install.WIM”,(uint)WIM.CreateFileAccess.Mount,(uint)WIM.CreateFileMode.OpenExisting,0,0,out creationResult);
if(WIMHandle==IntPtr.Zero)
{
Console.WriteLine(“无法打开WIM文件。LastError:+Marshal.GetLastWin32Error()+”/0x“+Marshal.GetLastWin32Error().ToString(“x”));
返回;
}
尝试
{
//设置TMP路径
if(!WIM.WIMSetTemporaryPath(WIMHandle,@“D:\ISOCpy\y”))
{
//句柄将在析构函数中关闭
Console.WriteLine(“无法设置WIM临时路径.LastError:+Marshal.GetLastWin32Error()+”/0x“+Marshal.GetLastWin32Error().ToString(“x”);
返回;
}
int imgnums=WIM.WIMGetImageCount(WIMHandle);
如果(imgnums至少,我知道了.)
必须使用其他“读取”权限打开文件:
IntPtr WIMHandle = WIM.WIMCreateFile(@"D:\ISOCpy\install.wim",
((uint)WIM.CreateFileAccess.Mount | (uint)WIM.CreateFileAccess.Read),
(uint)WIM.CreateFileMode.OpenExisting, 0, 0, out creationResult);