如何使用 VBScript 向文件添加自定义属性 [英] How do I add a custom property to a file using VBScript

查看:44
本文介绍了如何使用 VBScript 向文件添加自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在 Windows 资源管理器中右键单击文件并单击属性,然后单击自定义选项卡时,会出现一个属性列表.我想使用 VBScript 文件添加这些自定义属性之一.属性的名称必须是版本,值必须是版本号,例如 1.0.0.0.文件类型为 msi.

When you right click on a file in Windows Explorer and click properties and then click the Custom tab there is a list of properties. I want to add one of these custom properties using a VBScript file. The property's name must be Version and the value must be a version number such as 1.0.0.0. The file type is an msi.

推荐答案

要读取和写入自定义文件属性,您需要使用 DSOFile.OleDocumentProperties COM 对象="http://support.microsoft.com/kb/224351" rel="nofollow">dsofile.dll 库.

To read and write custom file properties, you need to use the DSOFile.OleDocumentProperties COM object that is provided by the dsofile.dll library.

以下是完成任务的示例代码:

Here's sample code to accomplish your task:

Set oFile = CreateObject("DSOFile.OleDocumentProperties")
oFile.Open("E:\Setup.msi")

oFile.CustomProperties.Add "Version", "1.0.0.0"
oFile.Save
oFile.Close

在运行此代码之前,请确保您已在系统中注册了 dsofile.dll:

Before running this code, make sure you have registered dsofile.dll in the system:

regsvr32 dsofile.dll

这篇 TechNet 文章中有关使用 dsofile.dll 的更多信息.

More info on using the dsofile.dll in this TechNet article.

这篇关于如何使用 VBScript 向文件添加自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆