I am writing some code in Java that launches a VBScript to initiate
printing of selected files. Rather than write a custom bit of VB for
each known application, I decided to use the ShellExecute function.

The problem is, this works on my development machine (Win2K), but I
cant get it to work on XP Home, XP Pro (SP1) or XP Home (SP2).

STRANGELY, if I try to launch anything other than .doc, .ppt, .xls it
seems to work! - Thanks Microsoft! ;-)

Any suggestions? I dont think I can use the 'run' alternative, as that
doesn't allow me to specify the 'print' parameter.

FYI, typing test.doc in DOS or in the 'start->run' section DOES launch
word, so I know the associations are ok.

ATTEMPT 1:
dim objShell, filesys, manifestFile, filetext
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\test.doc", "", "", "print", 1
set objShell = nothing

ATTEMPT 2:
dim objShell, filesys, manifestFile, filetext
set objShell = CreateObject("Shell.Application")
CreateObject("Shell.Application")_
.Namespace(0)_
.ParseName("C:\test.doc")_
.InvokeVerb "&Print"
set objShell = nothing

Re: ShellExecute fails to load & print microsoft products on XP!! (word/excel/powerpoint) by netplay

netplay
Wed May 04 04:17:02 CDT 2005

An update to this bug. If I run this script within the debugger it
works perfectly!

Also, if I add some lines to the end of the script nothing improves -
unless I add a debug msgbox. Why does this fix the problem!?

Revised Code:

dim objShell, filesys, manifestFile, filetext
set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\test.doc", "", "", "print", 1
set objShell = nothing
msgbox "Collect your printout"