|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||||||
|
||||||||
|
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:
and it gives runtime error 5 - invalid procedure call or argument. I try: VB Code:
and IE gives the open or save prompt. Is there a better way to do this? joe |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 ![]() |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
I'm glad you got it working. I didn't pay attention to the fact you were trying to open a url.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Shell command not working as expected |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|