受人尊敬的开源 .NET 包装器实现(夏普比特 http://sharpbits.codeplex.com/) of Windows BITS 服务 http://en.wikipedia.org/wiki/Background_Intelligent_Transfer_Service无法识别 Win7 x64 下的底层 BITS 版本。
这是失败的源代码。 NativeMethods 是由 .NET 方法包装并通过 DllImport 属性修饰的本机 Win32 调用。
private static BitsVersion GetBitsVersion()
{
try
{
string fileName = Path.Combine(
System.Environment.SystemDirectory, "qmgr.dll");
int handle = 0;
int size = NativeMethods.GetFileVersionInfoSize(fileName,
out handle);
if (size == 0) return BitsVersion.Bits0_0;
byte[] buffer = new byte[size];
if (!NativeMethods.GetFileVersionInfo(fileName,
handle,
size,
buffer))
{
return BitsVersion.Bits0_0;
}
IntPtr subBlock = IntPtr.Zero;
uint len = 0;
if (!NativeMethods.VerQueryValue(buffer,
@"\VarFileInfo\Translation",
out subBlock,
out len))
{
return BitsVersion.Bits0_0;
}
int block1 = Marshal.ReadInt16(subBlock);
int block2 = Marshal.ReadInt16((IntPtr)((int)subBlock + 2 ));
string spv = string.Format(
@"\StringFileInfo\{0:X4}{1:X4}\ProductVersion",
block1,
block2);
string versionInfo;
if (!NativeMethods.VerQueryValue(buffer,
spv,
out versionInfo,
out len))
{
return BitsVersion.Bits0_0;
}
...
实施遵循MSDN说明 http://msdn.microsoft.com/en-us/library/ms647464(VS.85).aspx通过信。仍在第二次 VerQueryValue(...) 调用期间,应用程序崩溃并终止调试会话不加思索。
在崩溃之前再提供一些调试信息:
- 特殊病毒 =>
“\StringFileInfo\040904B0\产品版本”
- buffer => byte[1900] - 充满二进制数据
- 块 1 => 1033
- 区块2 => 1200
我通过Windows查看了目标“C:\Windows\System32\qmgr.dll”文件(BITS的实现)。它说产品版本是7.5.7600.16385。该值应该在 versionInfo 字符串中返回,而不是崩溃。有什么建议吗?