Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / August 2006



Tip: Looking for answers? Try searching our database.

SHELL Command problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David L. Jones - 30 Aug 2006 07:02 GMT
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?

Thanks
Dave :)
Frank Adam - 30 Aug 2006 08:15 GMT
>I've got a problem with the SHELL command in VB6
>
[quoted text clipped - 10 lines]
>
>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.

Signature

Regards, Frank

David L. Jones - 30 Aug 2006 09:12 GMT
> >I've got a problem with the SHELL command in VB6
> >
[quoted text clipped - 16 lines]
> 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?

Is there another method?

Thanks
Dave :)
Frank Adam - 30 Aug 2006 10:03 GMT
>> >I've got a problem with the SHELL command in VB6
>> >
[quoted text clipped - 28 lines]
>
>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

Signature

Regards, Frank

David L. Jones - 30 Aug 2006 10:58 GMT
> >> >I've got a problem with the SHELL command in VB6
> >> >
[quoted text clipped - 42 lines]
>         debug.print "Failed. Errno: " & err.lastdllerror
> endif

That works a treat, thanks Frank!

Dave :)
Randy Birch - 31 Aug 2006 03:18 GMT
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

Signature

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

Please reply to the newsgroups so all can participate.

Frank Adam wrote:
> On 30 Aug 2006 01:12:58 -0700, "David L. Jones" <altzone@gmail.com>
> wrote:
[quoted text clipped - 49 lines]
> debug.print "Failed. Errno: " & err.lastdllerror
> endif

That works a treat, thanks Frank!

Dave :)
Frank Adam - 31 Aug 2006 09:48 GMT
Ha!   success <= 32, not success < 32.  

Hey Rick, it's ok. I got him back. ;-)

>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

Signature

Regards, Frank

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.