我的第一个答案错了.我给你的第一个建议是为你的应用程序制作一个“版本谎言”垫片.但你不能,因为你正在使用托管
代码应用程序.我不是说你不能为.NET应用程序编写API挂钩,但appcompat shim
支持似乎对托管应用程序来说很多.
应用程序填充程序实现API重定向,以便当应用程序进行某个API调用时,它会被截获或“被劫持”,并且其他一些数据将从填充程序返回给应用程序.
http://technet.microsoft.com/en-us/library/dd837644(v=WS.10).aspx
The Shim Infrastructure implements a form of application programming
interface (API) hooking. Specifically,it leverages the nature of
linking to redirect API calls from Windows itself to alternative
code—the shim itself.
大多数情况下,您可以使用应用程序兼容性工具包来编写自己的填充程序:
http://blogs.technet.com/b/askperf/archive/2011/06/17/demystifying-shims-or-using-the-app-compat-toolkit-to-make-your-old-stuff-work-with-your-new-stuff.aspx
并且做一个“版本谎言”,其中shim对于应用程序关于它运行的版本是appcompat shims的最常见用例.
因为开发人员坚持在他们的代码中进行版本检查,这是错误的.微软告诉你这是错的.不要在代码中进行版本检查. (相反,请检查您打算使用的特定功能的存在与否.)
但开发人员仍然每天都进行版本检查.更糟糕的是,他们进行“==”版本检查,除非您运行的是确切版本的Windows,这是任意且愚蠢的,否则应用程序根本无法运行.
叹息……开发者.
微软的克里斯杰克逊多年来一直从事应用程序兼容性工作,他的态度相似:
One of the classes of shims that people find the easiest to understand
are the version lie shims. In essence,we have shims that can
compensate for the fact that so many developers’ keyboards were
shipped with a defective > key (and the failure rate of this key on
developer keyboards is astonishing). They work by just returning a
different value from the GetVersion(Ex) APIs,depending on which
operating system you selected.
但不幸的是in that same article,他向我们提供了我认为的重要信息:
OK,so now that you have CompatAdmin started,under the System
Database,expand the Compatibility Fixes list. With the /x switch,
you’ll notice that the WinXPSP2VersionLie now has a plus sign – if you
expand this,you’ll see a list of modules that have a red diamond next
to them. These are modules that this shim specifically excludes. Among
these? The .NET Framework modules.
You see,the .NET Framework doesn’t take too kindly to being lied to.
They do version checks to determine how to implement certain things,
and thinking they’re running down-level isn’t so great. So,we
intentionally exclude these modules,and,consequently,we
intentionally exclude the code that you’re writing that these modules
are JITting and executing. Not that we wanted to do so,but the
infrastructure didn’t give us a great way to separate these out. We
either lied to everything,or we lied to nothing. It was worse to lie
to everything,so we didn’t.
呵呵,当我刚才说出一个想法有多糟糕的时候,那个.NET正在进行版本检查有点儿好笑……
For real-life applications that need a version lie,well,if the
application is managed,you’ll have to change the code. This is
something you can’t,and shouldn’t,shim up.
So,if you notice the version lie isn’t working,and the application
is managed,then my spidey sense tells me you’re trying to shim it up
with an XP version lie – and that’s not going to work.
从MSDN开始:
Generally,apps should not perform operating system version checks. If an app needs a specific feature,it is preferable to try to find the feature,and fail only if the needed feature is missing.