0

I have a legacy application which doesn't support utilizing the default applications defined in windows which requires that I specify a specific an executable for a file format to be opened within the application. Since Microsoft no longer includes MODI with Office by default I have been looking at using launching Windows Picture Viewer for .TIF, .TIFF, & .BMP files since it is built into Windows; however Microsoft does not have a direct executable for Windows Picture Viewer which can be called forcing me to create a script which executes the command which calls for Windows Picture Viewer to execute. After research the only way I have been able to call the application to open a specific file is by creating a batch file such as below:

GIFTS.BAT

rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen %~1

If I execute the above code such as GIFTS.BAT "C:\Example Directory\Sample File.tif" from a command prompt or from the application launches and the Sample File.tif opens without a problem; however a command prompt opens along with the file when launching from the application.

Upon which I tried to create a vbscript to hide the batch file from executing however I can't seem to pass my argument if the argument has a "space" within the argument.

GIFTS.VBS

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run """C:\GIFTS.BAT"" " & WScript.Arguments.Item(0), 0
Set WshShell = Nothing

If I try to execute the VBScript from a command prompt such as GIFTS.VBS "C:\Example Directory\Sample File.tif" the application never launches and the command prompt returns no message or error. If I simplify the execute command (removing spaces to GIFTS.VBS "C:\Sample_File.tif" the application launches as well as the file Sample_File.tif is displayed and there is no command prompt displayed when the application executes the VBScript.

My question is how can I pass an argument into the VBS script that in return passes the the batch file when the argument contains spaces (which there is always going to be spaces since the argument will be a file name and path)?

There might be an easier approach to what I want to accomplish; however I am looking for a solution that Windows 7 - 8.1 can utilize with no additional software to install or manage on each workstation. The batch files works great I just need to be able to hide the command prompt that opens along with the application as my end users won't know what to do with it.

Thanks!

Aeudian
  • 3
  • 2
  • possible duplicate of [VB Script does not recogonize the actual parameter](http://stackoverflow.com/questions/15289000/vb-script-does-not-recogonize-the-actual-parameter) – Ansgar Wiechers Nov 03 '14 at 21:01
  • %~1 has had its quotes (if there are any) stripped so it's safe to wrap it in quotes. This should make it work whether there are spaces in there or not. – Stephen Connolly Nov 03 '14 at 22:00

1 Answers1

0

Sometimes, nested levels of escaping characters requires intimate knowledge of the undocumented behavior of CMD or some voodoo. Another way to attack the problem is to guarantee that you won't have any spaces in the name of the file. Windows has a concept of a short path (no spaces or special chars) for which every existing file has a unique one.

Here's a modified version of your program for which invoked subcommand doesn't need quotes around the file name.

Set WshShell = CreateObject("WScript.Shell") 

Set fso = CreateObject("Scripting.FileSystemObject") 
Set fsoFile = fso.GetFile(WScript.Arguments.Item(0))

WshShell.Run """c:\GIFTS.BAT"" " & fsoFile.ShortPath, 0
Set WshShell = Nothing

You may wish to add your own error checking. The specified file must exist in order for the GetFile() command to succeed.

mojo
  • 4,050
  • 17
  • 24
  • That did it! I am now able to pass the file name with spaces using double quotes and the command prompt stays hidden within the application. – Aeudian Nov 03 '14 at 21:55