使用jscript检测exe的版本和公司名称 [英] Detecting the version and company name of an exe using jscript
问题描述
我知道如何使用jscript检索exe的版本,但我找不到任何方法来检索公司,内部名称或产品名称等其他信息。
I kwnow how to retrieve the version of an exe using jscript, but I can't find any way to retrieve other info like "Company", "Internal name" or "Product name".
function version_of( file_name )
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f;
try {
f = fso.GetFile( file_name )
} catch( e ) {
throw new Error( e.number, "Error retrieving version of file ``" + file_name + "'': " + e.description );
}
var v = fso.GetFileVersion( f );
if ( !v ) {
throw new Error( 1, "File ``" + file_name + "'' has not got a version" );
}
return v;
}
WScript.Echo( version_of( "c:\\windows\\system32\\winver.exe" ) );
也许我会编写自己的COM对象来完成工作......
Maybe I will write my own COM object to do the job...
推荐答案
可以使用 GetDetailsOf
方法 文件夹
对象。该方法采用与扩展属性关联的从零开始的索引号,并将属性值作为字符串返回。通常, GetDetailsOf
可用于检索可在详细的Shell视图中显示的任何类型的信息(查看 - >选择详细信息)。请参阅检索扩展文件属性。
Extended file properties, such as company name or product name, can be obtained in scripts using the GetDetailsOf
method of the Shell Folder
object. The method takes a zero-based index number associated with the extended property and returns the property value as a string. In general, GetDetailsOf
can be used to retrieve any type of information that can be displayed in the detailed Shell view (View -> Choose Details). See Retrieving Extended File Properties.
唯一的问题是不同的Windows版本提供不同的扩展文件属性集。例如,Windows XP有34个文件属性,Windows Vista— 266,Windows 7— 284.不仅属性索引可以不同,而且属性名称(Windows XP中的持续时间 = Windows Vista中的长度),这是非常令人困惑的。有关可用文件属性及其索引号的完整列表,请参阅此页面或使用类似这样的脚本:
The only problem is that different Windows versions offer different sets of extended file properties. For example, Windows XP has 34 file properties, Windows Vista — 266, Windows 7 — 284. Not only the property indexes can differ, but also the property names (Duration in Windows XP = Length in Windows Vista), which is quite confusing. For a full list of available file properties and their index numbers, see this page or use a script like this one:
var oShell = new ActiveXObject("Shell.Application");
var oFolder = oShell.Namespace("C:");
for (var i = 0; i < 300 /* some large number*/; i++)
WScript.Echo(i + " " + oFolder.GetDetailsOf(null, i));
无论如何,这是在Windows Vista上执行任务的示例代码。我找不到内部名称属性(可能没有正确搜索),因此包含文件版本和产品版本:
Anyway, here's sample code to perform your task on Windows Vista. I couldn't find the Internal Name property (might not have searched properly) so included the File Version and Product Version instead:
var COMPANY_NAME = 33;
var FILE_VERSION = 145;
var PRODUCT_NAME = 251;
var PRODUCT_VERSION = 252;
var oShell = new ActiveXObject("Shell.Application");
var oFolder = oShell.Namespace("C:\\Windows");
var oFile = oFolder.ParseName("notepad.exe");
WScript.Echo("Company name: " + oFolder.GetDetailsOf(oFile, COMPANY_NAME));
WScript.Echo("Product name: " + oFolder.GetDetailsOf(oFile, PRODUCT_NAME));
WScript.Echo("File version: " + oFolder.GetDetailsOf(oFile, FILE_VERSION));
WScript.Echo("Product version: " + oFolder.GetDetailsOf(oFile, PRODUCT_VERSION));
请注意,您可以使用 GetDetailsOf(null,property_index)
获取特定于语言环境的属性名称(这在非英语Windows版本上非常有用):
Note that you can use GetDetailsOf(null, property_index)
to get locale-specific property names (this can be useful on non-English Windows versions):
WScript.Echo(oFolder.GetDetailsOf(null, COMPANY_NAME) + ": " + oFolder.GetDetailsOf(oFile, COMPANY_NAME));
这篇关于使用jscript检测exe的版本和公司名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!