Re: SHELL Command problem



And if the call does fail, you can have the Open With dialog pop up using:

If success < 32 Then
Call Shell("rundll32.exe shell32.dll,OpenAs_RunDLL " & sFile,
vbNormalFocus)
End If


--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"David L. Jones" <altzone@xxxxxxxxx> wrote in message
news:1156931926.011688.62220@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Frank Adam wrote:
On 30 Aug 2006 01:12:58 -0700, "David L. Jones" <altzone@xxxxxxxxx>
wrote:

Frank Adam wrote:
On 29 Aug 2006 23:02:32 -0700, "David L. Jones" <altzone@xxxxxxxxx>
wrote:

I've got a problem with the SHELL command in VB6

It works fine for executables like this:
shell "notepad.exe"

But when I try to open other file types like TXT I get the error
message:
"Runtime error 5: Invalid procedure call or argument"

So shell "c:\test.txt" won't work for instance.

The target file isn't being used by another app either.

Anyone know what's going on?

Yep, Shell is a braindead function loosely based on the ShellExecute
API.

Try ShellExecute("open","c:\test.text",vbnullstring,vbnullstring,1)
Shellexecute is defined in the API viewer.

Thanks for that.
Gave it a try but the parameters you gave do not match the ShellExecute
API declaration that I copied in from the API Viewer. I got this
declaration:

Public Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As
String, ByVal nShowCmd As Long) As Long

Why the mis-match?

Ahh sorry, forgot the leading one. I also should have mentioned that
the return velue is quite useful, since the function returns larger
than 32 if the operation was succesful and < or = 32 if it failed. If
all is well, the return value is in fact the process ID.

So you should really do it like this :
dim ret as long
ret = ShellExecute(0,"open","c:\test.txt",vbnullstring,vbnullstring,1)
if ret > 32 then
debug.print "Ok"
else
debug.print "Failed. Errno: " & err.lastdllerror
endif

That works a treat, thanks Frank!

Dave :)

.



Relevant Pages

  • Re: CreateProcessA Lib "kernel32" problem
    ... do is to search for that function using the VB provided API Viewer. ... 02> ByVal lpApplicationName As String, ... 04> lpProcessAttributes As SECURITY_ATTRIBUTES, _ ... ByVal lpApplicationName As String (VB API Declaration) ...
    (microsoft.public.vb.winapi)
  • Re: CreateProcessA Lib "kernel32" problem
    ... The VB viewer defines some variables as the data type expected, eg As String ... do is to search for that function using the VB provided API Viewer. ... ByVal lpProcessAttributes As Long, _ ... ByVal lpApplicationName As String (VB API Declaration) ...
    (microsoft.public.vb.winapi)
  • Re: SHELL Command problem
    ... So shell "c:\test.txt" won't work for instance. ... Shell is a braindead function loosely based on the ShellExecute ... API declaration that I copied in from the API Viewer. ... "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal ...
    (comp.lang.basic.visual.misc)
  • Re: SHELL Command problem
    ... So shell "c:\test.txt" won't work for instance. ... Shell is a braindead function loosely based on the ShellExecute ... API declaration that I copied in from the API Viewer. ... "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal ...
    (comp.lang.basic.visual.misc)
  • Re: Printing an Attachment Automatically??
    ... The code you posted with your attachment extraction loop looks OK. ... The declaration for ShellExecute should be at the module level, ... Private Declare Function ShellExecute Lib "shell32.dll" _ ... ByVal lpFile As String, ByVal lpParameters As String, _ ...
    (microsoft.public.office.developer.outlook.vba)