Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open txt file with context menu and vbs

Status
Not open for further replies.

Hfnet

IS-IT--Management
Dec 31, 2003
369
GB
We use Maximizer crm and have text files with various import details within tags inside it. My boss has asked if I can make a script for someone to be able to read the information without the tags.

I thought about adding a context menu item so a user can right-click on the file to open it with a vbs exe which will import the relevant data and display it.

I have been playing with various methods but none that seem to work on both XP and Vista. In vista (Which I use and do my coding on) I am unable to use the UserAccounts.CommonDialog function, so my questions are:

1) How to add a right-click context item "open with mxi viewer" via a vbs script
2) How to get the script to recognise the openargs of the file name that was right-clicked so the contents can be read.

Many thanks

 
I haven't messed with this but it doesn't seem too tough. Well I'm not sure what a "vbs exe" might be, but... A couple of Googles turned a few things up. You might take a look at Verbs and File Associations.

I'd expect that a garden variety script is going to be limited to one of the possible invokation methods:
As a command line call, as specified in a command key.

When you set the command key it would probably have to specify a script host as the target with your script as a parameter since the Shell uses CreateProcess(). You'd specify the file-to-open parameter as "%1" as shown in that article.

[tt]wscript.exe "%ProgramFiles%\fuddco\maxfilterview.vbs" "%1"[/tt]

Aside from that your script runs just as any script started via the command prompt. To get the file-to-open you just use the WshArguments collection, returned by the WScript.Arguments property.


The trickiest part will probably be deployment, but for just a few machines you might walk around with your .VBS and a .REG file to do it manually.

A better option might be an IExpress package, but that's a topic in itself. See:

IExpress Technology and the IExpress Wizard

And don't miss:

Working with Setup Information (.inf) Files

IExpress Wizard is part of Windows XP and later.

In a more managed environment it might be possible to deploy this new Shell Verb's .VBS file and registry entry using GPO.
 
Thanks for that. I have actually managed to cobble together a script and got the arguments to work now.

I used exescript which makes the vbs into an executable, thus protecting the code etc.
I also used CreateInstallFree to make an install package, an that has a registry section in which I added to, so now someone can right-click on a Maximizer import file and then click on mxi viewer.

Thanks for the info, the %1 was the bit I was missing to pass the argument, seen it so many times but forgot what it was for!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top