Today to do a function, is to modify the image of the summary information, the beginning is to modify the EXIF information, but a lot of pictures do not have EXIF information, or do not specify the EXIF items, and find another way to modify the file summary information.
The first is the use of Ole32.dll, but depressed is that this method can modify a lot of file summary information, but can not modify the picture summary information, helpless under, have to find another method.
Finally in Cnblogs found an article, inside the detailed introduction of DSOFile.dll, so hurriedly download down, Microsoft official, free, open source, even stay with the demo, hehe.
Registering DLLs, writing asp:
<%
Set OPR = Server.CreateObject ("Dsofile.oledocumentproperties")
Opr.open ("E:/paimei_demo_001.jpg")
Response.Write ("Author:" & OPR. Summaryproperties.author)
OPR. Summaryproperties.author = "0123456789"
OPR. Save
Response. Write ("<br/>")
Response.Write ("Author:" & OPR. Summaryproperties.author)
%>
Oh, done!
Disadvantage: If the file address contains Chinese characters, it will be wrong, but can be resolved.
Http://www.microsoft.com/china/technet/community/columns/scripts/sg0305.mspx#EVB
Dsofile: Stories not previously told
At the beginning of our script-writing story , we imagined ourselves to be the most majestic journalist in the scripting World who was good at uncovering scandals. The story of the script is one step ahead of anyone in telling the most popular script story of today, and we've drawn readers with our in-depth behind-the-scenes reports that only Microsoft scripting experts can offer. In fact, the most worrying thing about us is how to politely say to the Pulitzer Prize committee, "Look, friend, although we cherish this award every year, we are going to give it to someone, and maybe you should award it to somebody else, even if it's a substitute." Don't New York have a newspaper? Maybe you can give them the prize. ”
But it turns out that things are not as we expected. This is not to say that we are disappointed with the story of the script ; we think our little column helped many people overcome the fear of using scripts for the first time, and made them understand that using scripts to manage Windows is not as difficult as managing windows with GUI tools (which is actually often simpler). We are very happy about this. At the same time, the editors of the New York Times said, "There's no better Scripting Guy!" We can't compete with them! "This is also a happy thing. So far, however, the New York Times does not seem to care much about us.
confess . In this case, perhaps we should also be responsible for some. Don't forget, we recently had a column titled I was kidnapped by Bigfoot Savage . This article did not surprise the "Pulitzer Prize winner".
However, this month the situation is different; the March script story is not related to being kidnapped by Bigfoot. We've got a really explosive news, and you're nowhere to be found, a great story (unless you do Google search or otherwise). Yes, this month we launch Dsofile: Stories that haven't been told before .
Did you hear the cry of pain just now? Maybe it was issued by some editorial board of the New York Times . If not an editorial board, the Scripting Guy Peter Costantini just found out that the Microsoft cafeteria no longer sells his favorite Italian-style pretzels.
What is Dsofile?
Dsofile is actually the file name (Dsofile.dll) of the Microsoft Developer support OLE file Property Reader 2.0 Sample. (You must admit that Microsoft's own know-how has come up with a very bizarre name.) However, do not be intimidated by this name OH. In fact, Dsofile (you can get it for free from the Microsoft Download Center) is an extremely useful tool for scripting people: it provides a quick and easy way to read and write a set of summary information properties for all your files.
Your first reaction to this may be "this is unbelievable, why didn't you tell us earlier?" "Your second reaction may be," then, what is the summary information attribute? If you don't know what the summary information attribute set for a file refers to, do the following. Open Windows Explorer or My computer to find a file. (which file is not important, but we recommend that you use Microsoft Office documentation because it takes only two minutes to figure it out.) Right-click the file and click Properties. In the dialog box that appears, click the Summary tab. You should see something that is similar to the following (click the Advanced button if it is different from the following):
This is the summary information, which, as you can see, adds a lot of useful metadata to the file. More importantly, these metadata can be used immediately. For example, if you carefully fill in fields such as "Subject", "category", and "keywords", you can perform a precise search, which makes it quick and easy to find files. Using the file Search command in Microsoft Office, you can search for documents based on these summary information properties, as shown below, and the new MSN search tool can also search for documents based on these properties.
In fact, this is exactly what the script writer wants to get, and in the letters we receive, dozens of of them ask how to write scripts that can be used to access summary information and how to write scripts that can be used to configure these summary information. Scripting tools built into the operating system do not have this capability. Indeed, the Shell object has the ability to read some of the fields in these summary information fields. However, the Shell object cannot perform a write operation to the summary information field. Windows Script Host, File system object, WMI, or any other tool built into the operating system will not resolve this issue. In addition, there are many good things, but there seems to be nothing to do.
This is the place where Dsofile. Dsofile is designed to provide scripting writers with a way to get a summary information property of a file. A set of properties is built into Dsofile that is exactly the same as the standard properties for Microsoft Office documents. (This is not surprising: after all, Dsofile was developed by the Office team.) Using Dsofile, you can bind to a document and retrieve information about the following:
Application Name |
Author |
Number of bytes |
Type |
Number of characters |
Number of characters (count spaces) |
Note |
Company |
Date Created |
Last Print time |
Date Last Saved |
Number of hidden slides |
Key words |
The last person to save |
Number of rows |
Manager |
Number of Multimedia clips |
Number of comments |
Pages |
Paragraph |
Presentation format |
Revision number |
Sharing documents |
Number of slides |
Theme |
Template |
Title |
Editor time |
Version |
Words |
As we said, these are the properties that can be found in Microsoft Office documents. However, we are not limited to retrieving information from Office documents. We can also use Dsofile to bind to other types of files, for example, you can bind to a. vbs file, a. mp3 file, or another file. The only thing to note is that Dsofile cannot get any other properties than the properties listed above. For example, a. jpg file has properties such as width, height, and color depth. Although these properties are useful, you cannot access these properties using Dsofile.
Hey, hold on, Dsofile's not a new gadget.
There may be some skeptics who say, "Stop." This is past. Dsofile has been launched for several years. "That's true: not only Dsofile has been available for years, but there are even sample scripts in our Script Center that show you how to use the utility. However, a new version of Dsofile was introduced quietly in early December; that's why we're publishing this column, and that's why we say we want to bring you the latest news. (It is assumed that the latest news will still be counted after two months.) I'll tell you without asking, that the new version of Dsofile is dedicated to the. NET programming language, but as far as we know, it doesn't add any new features to the previous version.
The difference between the two versions is on scripts that take advantage of the Dsofile feature. Assuming you have an older version of Dsofile, you have now downloaded and installed the new version. Your old Dsofile script (as provided by the Script Center) cannot be used with the new version of Dsofile, because there are some differences between the script code required to use the old version and the scripting code required to use the new version.
For example, the following script uses the old version of Dsofile to retrieve the name of the document author:
Set Objpropertyreader = CreateObject ("Dsolefile.propertyreader") Set objdocument = Objpropertyreader.getdocumentproperties _ ("C:/scripts/new_users.xls") wscript.echo "Author:" & Objdocument.authorset objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/Scripts/New_ Users.xls ") WScript.Echo" Author: "& ObjFile.SummaryProperties.Author
The following is the rewritten script, which is used for the new version of Dsofile:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") Wscript.Echo " Author: "& ObjFile.SummaryProperties.Author
As you can see, two scripts return the author of the document, which is probably the only similarity between the two. Two scripts even Progids–dsolefile.propertyreader and dsofile.oledocumentproperties– are different. Unfortunately, the short document released with Dsofile does not make this clear; if you are not careful, you might install a new version like a Scripting Guy-at least one of the Scripting Guys has made such a mistake and spent hours trying to find out why the old script didn't work.
Those who are genuinely skeptical may still be thinking, "Fuss!" Can't you just create an instance of an Office application to get the same information? Can However, the value of using Dsofile is not that it can get unique information that other applications, such as Microsoft Office, cannot get, but that it only has this capability. Scripts that use Dsofile return information faster than scripts that use Microsoft Office, because you do not need to create a Word or instance of Excel just to determine the author of the document. Dsofile makes it quicker and easier to get the same information, while also saving you the overhead of starting Office applications. That's why Dsofile becomes such a useful tool.
Very good, but how to use Dsofile?
Good question! If we want to get this year's scripted Pulitzer Prize, it might help to provide you with some code. (If they do have a Pulitzer Prize in scripting, they will also help us achieve this "winning Dream".) Now let's take a closer look at the script that we can return to the author of the document:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") Wscript.Echo " Author: "& ObjFile.SummaryProperties.Author
As you can see, we first created an instance of the dsofile.oledocumentproperties object. We then " Open" The file using the Open method. (We quoted the word "open" in quotation marks because we didn't open the file in the following way: Start an application such as Microsoft Excel, and then load the document.) The only action we perform is to bind to the summary information metadata that accompanies the file. )
After the connection is complete, we only echo the value of the required summary information property. There's nothing special here. The only thing to note is that we need to refer to the Summaryproperties object; so we used objfile. summaryproperties. Author instead of using Objfile.author. But it's just a trick; there are no arrays, no strange date conversions, and there are some things about scripting that we've all started to like.
The following is a more complete script that retrieves all the summary information values for the file C:/scripts/new_users.xls. Another good feature of Dsofile is that if you try to echo properties such as Slidecount for a slide-independent file, it does not generate an error. You just get a Null value (or 0 if it is a numeric attribute) and the script continues to run smoothly. This is true even if you retrieve information for a text file, a Windows Media file, or any other non-Microsoft Office document.
The code is as follows:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") Wscript.Echo " Application name: "& ObjFile.SummaryProperties.ApplicationNameWscript.Echo" Author: "& ObjFile.SummaryProperties.AuthorWscript.Echo "Byte count:" & ObjFile.SummaryProperties.ByteCountWscript.Echo " Category: "& ObjFile.SummaryProperties.CategoryWscript.Echo" Character count: "& ObjFile.SummaryProperties.CharacterCountWscript.Echo "Character count with Spaces:" & ObjFile.SummaryProperties.CharacterCountWithSpacesWscript.Echo "Comments:" & ObjFile.SummaryProperties.CommentsWscript.Echo "Company:" & ObjFile.SummaryProperties.CompanyWscript.Echo " Date Created: "& ObjFile.SummaryProperties.DateCreatedWscript.Echo" date Last printed: "& ObjFile.SummaryProperties.DateLastPrintedWscript.Echo "Date Last Saved:" & ObjFile.SummaryProperties.DateLastSavedWscript.Echo "Hidden Slide Count:" & ObjFile.SummaryProperties.HiddenSlideCOuntwscript.echo "Keywords:" & ObjFile.SummaryProperties.KeywordsWscript.Echo "Last Saved by:" & ObjFile.SummaryProperties.LastSavedByWscript.Echo "line count:" & ObjFile.SummaryProperties.LineCountWscript.Echo "Manager:" & ObjFile.SummaryProperties.ManagerWscript.Echo " Multimedia clip count: "& ObjFile.SummaryProperties.MultimediaClipCountWscript.Echo" Note count: "& ObjFile.SummaryProperties.NoteCountWscript.Echo "page Count:" & ObjFile.SummaryProperties.PageCountWscript.Echo "Paragraph count:" & ObjFile.SummaryProperties.ParagraphCountWscript.Echo "Presentation format:" & ObjFile.SummaryProperties.PresentationFormatWscript.Echo "Revision Number:" & ObjFile.SummaryProperties.RevisionNumberWscript.Echo "Shared Document:" & ObjFile.SummaryProperties.SharedDocumentWscript.Echo "Slide count:" & ObjFile.SummaryProperties.SlideCountWscript.Echo "Subject:" & ObjFile.SummaryProperties.SubjectWscript.Echo " Template: "& OBJFIle. SummaryProperties.TemplateWscript.Echo "Title:" & ObjFile.SummaryProperties.TitleWscript.Echo "total edit time:" & ObjFile.SummaryProperties.TotalEditTimeWscript.Echo "Version:" & ObjFile.SummaryProperties.VersionWscript.Echo "Word count:" & ObjFile.SummaryProperties.WordCount
Of course, retrieving summary information is only half the success; as a script writer, you also want to be able to configure these property values. You are very lucky, my friend. Do you want to assign a caption to a document? Just use a script like this:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") ObjFile.SummaryProperties.Title = "New Title added via a script" Objfile.save
We create an instance of the Oledocumentproperties object again, and then call the open method for opening the file. We assign the title New title added via a script to Summaryproperties.title, and then call the Save method. That's all you can do. If we decide to delete the document title, we simply set the property value to an empty string, as follows:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") ObjFile.SummaryProperties.Title = "" Objfile.save
One drawback of Dsofile is that it can only write a summary information field for Microsoft Office documents. If you try to use a script to specify a caption for another file (such as a text file, a. txt file), a failure occurs. This is really a sad thing in life. Also, note that not all properties are writable, and some properties are read-only. You can use Dsofile to change the title or subject of the document, but you cannot – for obvious reasons – use Dsofile to change the number of bytes or create date properties.
It's not finished yet.
General scripting reporters – such as those who work in the main scripting news organizations – may well feel that they are clear about everything you need to know about Dsofile. However, do you think the "Scripting Guy" is a lightly-abandoned team?
Actually, we are. But our editor says, "What about custom document properties?" Don't you think people are interested in customizing document properties? "Because she was tall, almost 11 feet high, and two eyes were spouting fire, so we agreed," Well, you say what. (We would also point out that since she did not delete "nearly 11 feet, two jets of fire", it is certainly true.) )
So what about these custom document properties? As we described earlier, the Microsoft Office document has dozens of built-in document properties. But what if these document properties don't exactly meet your needs? No problem, you can add your own properties to Microsoft Office documents.
For example, suppose you want to track the last view date of a document. The built-in document properties do not include a property named View Date . It doesn't matter, we can create such a property ourselves:
Const msoPropertyTypeDate = 3Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/Scripts/New _users.xls ") ObjFile.CustomProperties.Add" Date reviewed ", msoPropertyTypeDate Objfile.save
We first define a constant named msopropertytypedate , assigning the value 3 to it; This is to tell Dsofile that the custom attribute we are adding is a date field. A custom property can be any of the following types:
Constant |
Data type |
Value |
Msopropertytypenumber |
Digital |
1 |
Msopropertytypeboolean |
Boolean (yes/No) |
2 |
msoPropertyTypeDate |
Date |
3 |
msoPropertyTypeString |
String |
4 |
In other words, if we want to add the document reviewed property, and we just want it to indicate whether it has been modified, then we can add the Boolean property as follows:
Const Msopropertytypeboolean = 2Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/Scripts/ New_users.xls ") ObjFile.CustomProperties.Add" Document reviewed ", Msopropertytypebooleanobjfile.save
Now go back to the "View Date" property. We then bind to the document, access the CustomProperties collection, call the Add method, pass two parameters: the name we specify for the new property (the view date) and the data type of the new attribute (msoPropertyTypeDate). We then call the save method to save the new property to the CustomProperties collection.
When we run a script that can create a new custom property, the action we take is actually to set aside a place where the information can be stored; By default, no information is actually stored there. (In other words, we have a place to save the "view Date", but that place will be empty.) In addition, this new property does not appear in the Properties dialog box, at least until you assign it a value. So we'd better show you how to assign a value to this new property.
To assign a value, we need to use a script similar to the following code:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") set ObjProperty = ObjFile.CustomProperties.Item ("Date reviewed") Objproperty.value = #2/16/2005#objfile.save
We first bind to the file C:/scripts/new_users.xls. We then create a property reference to our custom property, which is what the following line of code does:
Set objproperty = ObjFile.CustomProperties.Item ("Date reviewed")
We set the Valueof the property and then call the save method to save our changes. That's it. The view Date property now holds the value 2/16/2005. After assigning a value to this property, we can view the New_users.xls Properties dialog box. When you view it, you will see something similar to the following:
By the way, using two pound numbers (#) to enclose dates is a standard VBScript method that is designed to ensure that dates are passed as dates rather than as strings or as a mathematical expression (for example, 2 divided by 16, divided by 2005).
You're right: it's really more like a Nobel Prize than a Pulitzer Prize. But it can get better. (Those who think "what would be better than winning a Nobel Prize?") "The readers didn't take Dsofile seriously, did they?" You do not need to use Windows Explorer to retrieve the values of all the custom properties that accompany the document, and you can use a script that resembles the following code:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") for each Objproperty in Objfile.customproperties WScript.Echo Objproperty.name, Objproperty.valuenext
Because CustomProperties is a collection, we use the For Each loop to iterate through all the items in the collection, echoing the property name and the value assigned to it. It's very simple, isn't it?
What if you want to delete this custom attribute? Bind to the document, set an object reference to the property you want to delete, and then call the remove method:
Set objfile = CreateObject ("Dsofile.oledocumentproperties") Objfile.open ("C:/scripts/new_users.xls") set ObjProperty = ObjFile.CustomProperties.Item ("Date reviewed") ObjProperty.RemoveobjFile.Save
Again, make sure that you call the save method to save the changes to the custom property set.
We should thank the Pulitzer Prize Committee ...
... But we can't thank them because they haven't actually presented us with the Pulitzer Prize. However, we do hope that you will find Dsofile useful. One of the things we're trying to do is help you expand your scripting scope a bit. As you may recall, we introduced the Log Parserlast month, which is a tool that the operating system does not ship with but is extremely useful to script writers. Try Dsofile and tell us how you feel about it (as always, you can send your email to the following address:[email protected]).
If you do find it useful, you may want to mention the Scripting Guy the next time you talk to a member of the Pulitzer Prize committee. In that case, we'd really have to pack up the dresses we bought in our hurry and dress up.
DSOfile, modifying Windows System files Summary