Reading and Modifying a Microsoft Word Document using TCL Script - shell

I am working on an Automation project which i coded fully in TCL. A part of the project demands to read a Microsoft Word Document and modify a line in that Word Document using TCL Script. I tried with tcom packages but i faced problem while making changes to that document since the word document gets corrupt. So guys if anybody can help me i will be very thankful.
Note : The script can also be in Shell. In that case i will invoke the shell script from my tcl script.
Thanks

tcom is a windows only extension to allow Tcl to interact with COM objects. To automate Microsoft Word using tcom you are actually running the Word executable so this can only be done on Windows.
To do this on unix, you will need to find some unix application that can modify Word documents for you. Tcl will not have any unix extensions that can do this and the file format you have to operate on will depend on the version of Word used. If the file is a docx file then that is actually a zip format file with XML documents in it. You can use the zipvfs subcomponent of the tclvfs extension to mount the zip document and then you could use tdom (tcl XML document object model extension) to examine and modify the XML stream in place. For previous versions of word that used structured storage documents you face an uphill struggle to handle the format on non-windows systems.

Manipulating MS Office documents on Unix is a bit of a pain, and there are no Tcl packages for doing so (as far as I know). Your best bet might be to use something like Apache POI for the integration work, and driving that Java library either as an external process (i.e., write a small Java app that integrates) or by running your Tcl inside a JTcl interpreter within the Java process.

Related

Is it possible to change an .rtf file to .txt file using some sort of batch script on Windows?

We have a .rtf file that needs to be downloaded from a Windows machine, but it contains a lot of pictures in it so it is 2 GB. I would like to download just the text from this file, so it would be ideal if there was an automated script that ran each day on the Windows machine that could convert this file from rtf to txt. Is there a way to do this?
If you can use PowerShell, sure. PowerShell gives you access to the .NET Framework. You can use System.Windows.Forms.RichTextBox to perform the conversion. Your application (or PowerShell code) need not be a Windows Forms application.
Here is a a full example.
You can use unrtf.
unrtf --text /path/to/rtf
Depending on your skill level, you can
Use Office Automation to build a script in Word to load the RTF and
then save as TXT
Use .NET to load a copy of Word and then save as TXT
Use .NET and regular expressions to filter unnecessary information
Use .NET to load the RTF in Internet Explorer and then Save As

How to Embed/Wrap the VB Script into Exe and Extract during the run time

I would like to convert the VB Script ( .VBS file) into EXE. If any one has any idea on how to convert VBS to Exe, Please share with me.
Some VBS IDEs allow this by default (vbsedit is one example) and there are also lots of tools that would do the conversion I even found a web page for that purpose. The list is quite long, if you google vbs to exe you will find many more.
Please keep in mind that this is not a compilation. Most will either pack the scripting host and the exe together or even just be the vbs file in a self extracting archive (you could also do this yourself with 7zip e.g.) This means the code will probably still be easily obtainable so it is not save to use this with cleartext passwords.
I also found this tool which claims to encrypt/obfuscate the script, but I cannot say how secure it really would be.
As a side note: If you encrypt the script any error message will be with the completely wrong line number, which confused some people I know who used these methods. So for debugging always use the original script.

How to zip a file in windows shell without vb script and with Window default zip only

Is their a way to zip a file without VB Script.I got a lot of examples on web to zip file or folder using vbs but i want to do it in a single BAT file.
Yes and no. There is no built in way to do this inside windows. You can use a external application like vbscript, a exe file like 7zip, rar, lots of resources can do this. Since windows is application poor when it comes to command lines is not really surprising. But no you do not need the VB Script for anything.
Just not so easy out of the box. Maybe makecab could do it for you? As a general rule you have a hard constraint in your question. A single BAT file which in general can not do almost anything without the support of hundreds of preinstalled or commonly installed other applications.
Could you specify a the constraints a bit better. Tel WHY you need this particular constraint? And what does it mean as even most of the bat command you use require more than one file.

how to overcome command line string limitation?

Command line has a string limitation as mentioned on msdn and here.
I tried the workaround suggested on msdn, writing the arguments to a file. But, I am unable to pass the arguments from a file.
Edit :
I need to run the bcp utility, in order to export (huge) data to flat files.
The executable you're running has to support this explicitly. For example, the C# compiler allows you to write
csc #foo
to load some options from a file called foo. I don't believe this can easily be "fixed" without support from the command you're running though... it's possible that you could write a small wrapper program which loaded the file and started the process itself. However, you'd have to be careful in terms of security handles, propagating console input and output etc. If you're in control of the application in question, you'd be much better off putting support in directly.

Can VS_VERSION_INFO be added to non-exe files?

My windows co-workers were asking me if I could modify my non-windows binary files such that when their "Properties" are examined under Windows, they could see a "Version" tab like that which would show for a Visual Studio compiled exe.
Specifically, I have some gzipped binary files and was wondering if I could modify them to satisfy this demand. If there's a better way, that would be fine, too.
Is there a way I could make my binaries appear to be exe files?
I tried simply appending the VS_VERSION_INFO block from notepad.exe to the end of one of my binaries in the hope that Windows scans for the block, but it didn't work.
I tried editing the other information regarding Author, Subject, Revision, etc. That doesn't modify the file, it just creates another data fork(what's the windows term?) for the file in NTFS.
It is not supported by windows, since each file type has their own file format. But that doesn't mean you can't accomplish it. The resources stored inside dlls and exes are part of the file format.
Display to the user:
If you wanted this information to be displayed to the user, this would probably be best accomplished with using a property page shell extension. You would create a similar looking page, but it wouldn't be using the exact same page. There is a really good multi part tutorial on shell extensions, including property pages starting with that link.
Where to actually store the resource:
Instead of appending a block to the file, you could store the resource into a separate alternate data stream on the same file. This would leave the original file stream non corrupted on disk and not cause its primary file size to change.
Alternate data streams allow more than one data stream to be associated with a filename. Each stream is identified by a colon : at the end of the filename and an identifier.
You can create them for example by doing:
notepad test.txt:adsname1
notepad test.txt:adsname2
notepad test.txt
Getting the normal Win32 APIs working:
If you wanted the normal API to work, you'd have to intercept the Win32 APIs: LoadLibraryEx, FindResource, LoadResource and LockResource. This is probably not worth the trouble though since you are already creating your own property page.
Can't think of any way to do this short of a shell extension. The approach I've taken in the past is a separate "census" program that knows how to read version information from any kind of file.
Zip files can be converted into exe files by using a program that turns a zip file into a self-extracting zip (I know that WinZip does this, there are most likely free utilities for this also; here's one that came up on a search but I haven't actually tried it). Once you've got an exe, you should be able to use a tool like Resource Hacker to change the version information.
It won't work. Either Windows would have to know every file format or no file format would be disturbed if version information were appended to it.
No, resource section is only expected inside PE (portable executable; exe, dll, sys).
It is more then just putting the data inside the file, you have a table that points to the data in the file header.
What you can do if you have NTFS drive, is to use NTFS stream to store custom properties this way the contact of the binary file will remain the same, but you will need to use a custom shell extension to show the content of the stream.

Resources