Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old March 30th, 2006, 07:43 PM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 360 cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 39 sec
Reputation Power: 5
Shell command not working as expected

I'm trying to use the Shell() function in VB6 to launch a URL shortcut. I'm using:
VB Code:
Original - VB Code
  1. RetVal = Shell("C:\Documents and Settings\Joe Reynolds\Desktop\cable_a_listings.url", 1)


and it gives runtime error 5 - invalid procedure call or argument.

I try:
VB Code:
Original - VB Code
  1. RetVal = Shell("C:\program files\internet explorer\Iexplore.exe C:\Documents and Settings\Joe Reynolds\Desktop\cable_a_listings.url", 1)


and IE gives the open or save prompt.

Is there a better way to do this?

joe

Reply With Quote
  #2  
Old March 30th, 2006, 11:47 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
By the time windows sees your command, it needs to see quotes around the path since there are spaces in the folder names. Try
Code:
RetVal = Shell("""C:\Documents and Settings\Joe Reynolds\Desktop\cable_a_listings.url""", 1)
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old April 3rd, 2006, 09:24 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
I found this some time ago in another bulletin board

Module

----------------------

'Danke sehr http://www.vbarchiv.net/vbapi/ShellExecute.php

'lpOperation The operation to perform on lpFile. This can be one of the following strings, although other options are possible, depending on the file being acted upon:
'"explore" If lpFile is a path name, open it in a Windows Explorer window.
'"open" Open lpFile using its associated program. Opening an executable file runs it. This is the default action if none is specified.
'"print" Print lpFile using its associated program.

'lpFile The name of the file to open, print, execute, or whatever is specified by lpVerb.

'lpParameters Additional parameters to use to perform the action. This would typically be additional command-line options to use, especially when running an executable file.


Private 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

Private Const SW_HIDE = 0
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOWNORMAL = 1

Private Const ERROR_BAD_FORMAT = 11&
Private Const SE_ERR_ACCESSDENIED = 5
Private Const SE_ERR_ASSOCINCOMPLETE = 27
Private Const SE_ERR_DDEBUSY = 30
Private Const SE_ERR_DDEFAIL = 29
Private Const SE_ERR_DDETIMEOUT = 28
Private Const SE_ERR_DLLNOTFOUND = 32
Private Const SE_ERR_FNF = 2
Private Const SE_ERR_NOASSOC = 31
Private Const SE_ERR_OOM = 8
Private Const SE_ERR_PNF = 3
Private Const SE_ERR_SHARE = 26

Private Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" _
(ByVal lpFile As String, ByVal lpDirectory As String, ByVal lpResult As String) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" _
(ByVal lpString As Any) As Long

' FindExecutable Konstanen
Private Const ERROR_FILE_NOT_FOUND = 2&
Private Const ERROR_PATH_NOT_FOUND = 3&

Public Sub Execute(HWND As Long, PathName As String, FileName As String)
Dim Retval As Long
Dim ASSOCIATEDPROG As String
ASSOCIATEDPROG = FindAssociatedProg(PathName, FileName)
MsgBox ASSOCIATEDPROG
Retval = ShellExecute(HWND, "open", Chr(34) & ASSOCIATEDPROG & Chr(34), _
Chr(34) & PathName & "\" & FileName & Chr(34), Chr(34) & PathName & Chr(34), SW_SHOWNORMAL)

Select Case Retval
Case SE_ERR_NOASSOC
MsgBox "Datei ist nicht Assizoiert", vbInformation, "Fehler"
Exit Sub
Case SE_ERR_PNF
MsgBox "Pfad wurde nicht gefunden", vbInformation, "Fehler"
Exit Sub
Case SE_ERR_FNF
MsgBox "Datei wurde nicht gefunden", vbInformation, "Fehler"
Exit Sub
Case 8, 26, 32, 28, 29, 30, 27, 5, 11 ' alle anderen Fehler
Exit Sub
End Select
End Sub

Function FindAssociatedProg(PathName As String, FileName As String) As String
Dim Retval As Long, Puffer As String
Puffer = Space(256)
Retval = FindExecutable(FileName, PathName, Puffer)
If Retval = 42 Then FindAssociatedProg = Left$(Puffer, lstrlen(Puffer))
End Function


-------------------------------------

In your program

Execute Me.HWND, File1.Path, File1.FileName

Reply With Quote
  #4  
Old April 4th, 2006, 10:22 AM
cjreynolds cjreynolds is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 360 cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level)cjreynolds User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 11 h 31 m 39 sec
Reputation Power: 5
No luck, Doug G - but I found that I can use the URL intead of using the shortcut to do what I need.. Thanks anyway!

joe

Reply With Quote
  #5  
Old April 4th, 2006, 04:56 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 19 m 36 sec
Reputation Power: 181
I'm glad you got it working. I didn't pay attention to the fact you were trying to open a url.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Shell command not working as expected


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT