Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    271

    [VB6] ShelEx su Win7

    Salve a tutti,
    ho una mia applicazione in VB6 (si lo so è roba vecchia ma per ora non se ne parla di aggiornarla) installata su Windows 7. Per aprire dei file allegati uso la ShellExecute, il problema è che quando si tratta di aprire un file pdf, mi ritorna l'errore SE_ERR_NOASSOC = 31 "No application is associated with this file type."

    Sembra che non si sia installato Adobe reader, che invece è installato correttamente in fatti se prova ad aprire il file manualemente da windows si apre senza problemi.
    Pensavo a problemi di compatibilità con windows 7 e adobe reader.
    La versione di Adobe Reader installata è la 9.3.2
    Su un altro pc, dove è installato Windows XP e la stessa versione di Adobe reader tutto funziona bene.
    Windows 7 è a 32 bit.

    Qualcuno sa come ovviare?
    Qualsiasi info sarebbe gradita
    Grazie 100

    DIEGO
    Signori si nasce! E io modestamente, lo nacqui!!!
    Totò

  2. #2
    Utente di HTML.it L'avatar di gibra
    Registrato dal
    Apr 2008
    residenza
    Italy
    Messaggi
    4,244
    Non mi risultano esservi problemi di compatibilità.
    Io ho Acrobat Reader su Windows 64bit e ShellExecute() funziona correttamente.

    Mostra il codice che usi...


    Come primo tentativo proverei a re-installare Acrobat Reader.
    Poi vediamo...


  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    271
    Grazie per la risposta. Il codice che uso è il seguente ed ha sempre funzionato:

    codice:
    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 Declare Function ShellExecuteForExplore Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, lpParameters As Any, lpDirectory As Any, ByVal nShowCmd As Long) As Long
    
    Public Enum EShellShowConstants
         essSW_HIDE = 0
         essSW_MAXIMIZE = 3
         essSW_MINIMIZE = 6
         essSW_SHOWMAXIMIZED = 3
         essSW_SHOWMINIMIZED = 2
         essSW_SHOWNORMAL = 1
         essSW_SHOWNOACTIVATE = 4
         essSW_SHOWNA = 8
         essSW_SHOWMINNOACTIVE = 7
         essSW_SHOWDEFAULT = 10
         essSW_RESTORE = 9
         essSW_SHOW = 5
    End Enum
    
    Private Const ERROR_FILE_NOT_FOUND = 2&
    Private Const ERROR_PATH_NOT_FOUND = 3&
    Private Const ERROR_BAD_FORMAT = 11&
    Private Const SE_ERR_ACCESSDENIED = 5            '  access denied
    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                     '  file not found
    Private Const SE_ERR_NOASSOC = 31
    Private Const SE_ERR_PNF = 3                     '  path not found
    Private Const SE_ERR_OOM = 8                     '  out of memory
    Private Const SE_ERR_SHARE = 26
    
    Public Function ShellEx( _
            ByVal sFile As String, _
            Optional ByVal eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT, _
            Optional ByVal sParameters As String = "", _
            Optional ByVal sDefaultDir As String = "", _
            Optional sOperation As String = "open", _
            Optional Owner As Long = 0 _
        ) As Boolean
    
    Dim lR As Long
    Dim lErr As Long, sErr As String
        If (InStr(UCase$(sFile), ".EXE") <> 0) Then
            eShowCmd = 0
        End If
        'On Error Resume Next
        If (sParameters = "") And (sDefaultDir = "") Then
            lR = ShellExecuteForExplore(Owner, sOperation, sFile, 0, 0, essSW_SHOWNORMAL)
        Else
            lR = ShellExecute(Owner, sOperation, sFile, sParameters, sDefaultDir, eShowCmd)
        End If
        If (lR < 0) Or (lR > 32) Then
            ShellEx = True
        Else
            ' raise an appropriate error:
            lErr = vbObjectError + 1048 + lR
            Select Case lR
            Case 0
                lErr = 7: sErr = "Out of memory"
            Case ERROR_FILE_NOT_FOUND
                lErr = 53: sErr = "File not found"
            Case ERROR_PATH_NOT_FOUND
                lErr = 76: sErr = "Path not found"
            Case ERROR_BAD_FORMAT
                sErr = "The executable file is invalid or corrupt"
            Case SE_ERR_ACCESSDENIED
                lErr = 75: sErr = "Path/file access error"
            Case SE_ERR_ASSOCINCOMPLETE
                sErr = "This file type does not have a valid file association."
            Case SE_ERR_DDEBUSY
                lErr = 285: sErr = "The file could not be opened because the target application is busy.  Please try again in a moment."
            Case SE_ERR_DDEFAIL
                lErr = 285: sErr = "The file could not be opened because the DDE transaction failed.  Please try again in a moment."
            Case SE_ERR_DDETIMEOUT
                lErr = 286: sErr = "The file could not be opened due to time out.  Please try again in a moment."
            Case SE_ERR_DLLNOTFOUND
                lErr = 48: sErr = "The specified dynamic-link library was not found."
            Case SE_ERR_FNF
                lErr = 53: sErr = "File not found"
            Case SE_ERR_NOASSOC
                sErr = "No application is associated with this file type."
            Case SE_ERR_OOM
                lErr = 7: sErr = "Out of memory"
            Case SE_ERR_PNF
                lErr = 76: sErr = "Path not found"
            Case SE_ERR_SHARE
                lErr = 75: sErr = "A sharing violation occurred."
            Case Else
                sErr = "An error occurred occurred whilst trying to open or print the selected file."
            End Select
                    
            Err.Raise lErr, , App.EXEName & ".GShell" & vbLf & sErr
            ShellEx = False
        End If
    
    End Function
    Signori si nasce! E io modestamente, lo nacqui!!!
    Totò

  4. #4
    Utente di HTML.it L'avatar di gibra
    Registrato dal
    Apr 2008
    residenza
    Italy
    Messaggi
    4,244
    Sinceramente non capisco il motivo della doppia dichiarazione.

    Io ho sempre usato la dichiarazione classica e funziona con tutti i tipi di file sia eseguibili, sia documenti.

    Inoltre non hai indicato come, quando e perchè chiami la tua routine ShellEx.

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    271
    Questa funzione la richiamo sul click di un button con il codice

    ShellEx File

    Questo codice l'avevo trovato tempo fa in rete e aveva sempre funzionato, mi accorgo ora della doppia dichiarazione ShellExecute e ShellExecuteForExplore

    Ad ogni modo in base ai paramentri che passo, viene eseguita sempre la ShellExecuteForExplore.

    Potrebbe essere questo il problema?
    Magari facci ouna prova
    Signori si nasce! E io modestamente, lo nacqui!!!
    Totò

  6. #6
    Utente di HTML.it
    Registrato dal
    Oct 2002
    Messaggi
    271
    niente da fare, ho modificato il codice lasciando una sola dichiarazione, ma l'errore è sempre lo stesso.
    Ecco il codice aggiortato:

    codice:
    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
    
    Public Enum EShellShowConstants
         essSW_HIDE = 0
         essSW_MAXIMIZE = 3
         essSW_MINIMIZE = 6
         essSW_SHOWMAXIMIZED = 3
         essSW_SHOWMINIMIZED = 2
         essSW_SHOWNORMAL = 1
         essSW_SHOWNOACTIVATE = 4
         essSW_SHOWNA = 8
         essSW_SHOWMINNOACTIVE = 7
         essSW_SHOWDEFAULT = 10
         essSW_RESTORE = 9
         essSW_SHOW = 5
    End Enum
    
    Private Const ERROR_FILE_NOT_FOUND = 2&
    Private Const ERROR_PATH_NOT_FOUND = 3&
    Private Const ERROR_BAD_FORMAT = 11&
    Private Const SE_ERR_ACCESSDENIED = 5            '  access denied
    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                     '  file not found
    Private Const SE_ERR_NOASSOC = 31
    Private Const SE_ERR_PNF = 3                     '  path not found
    Private Const SE_ERR_OOM = 8                     '  out of memory
    Private Const SE_ERR_SHARE = 26
    
    Public Function ApriAllegato( _
            ByVal sFile As String, _
            Optional ByVal eShowCmd As EShellShowConstants = essSW_SHOWDEFAULT, _
            Optional ByVal sParameters As String = "", _
            Optional ByVal sDefaultDir As String = "", _
            Optional sOperation As String = "open", _
            Optional Owner As Long = 0 _
        ) As Boolean
    
    Dim lR As Long
    Dim lErr As Long, sErr As String
        If (InStr(UCase$(sFile), ".EXE") <> 0) Then
            eShowCmd = 0
        End If
        'On Error Resume Next
    
        lR = ShellExecute(Owner, sOperation, sFile, 0, 0, essSW_SHOWNORMAL)
    
        If (lR < 0) Or (lR > 32) Then
            ApriAllegato = True
        Else
            ' raise an appropriate error:
            lErr = vbObjectError + 1048 + lR
            Select Case lR
            Case 0
                lErr = 7: sErr = "Out of memory"
            Case ERROR_FILE_NOT_FOUND
                lErr = 53: sErr = "File not found"
            Case ERROR_PATH_NOT_FOUND
                lErr = 76: sErr = "Path not found"
            Case ERROR_BAD_FORMAT
                sErr = "The executable file is invalid or corrupt"
            Case SE_ERR_ACCESSDENIED
                lErr = 75: sErr = "Path/file access error"
            Case SE_ERR_ASSOCINCOMPLETE
                sErr = "This file type does not have a valid file association."
            Case SE_ERR_DDEBUSY
                lErr = 285: sErr = "The file could not be opened because the target application is busy.  Please try again in a moment."
            Case SE_ERR_DDEFAIL
                lErr = 285: sErr = "The file could not be opened because the DDE transaction failed.  Please try again in a moment."
            Case SE_ERR_DDETIMEOUT
                lErr = 286: sErr = "The file could not be opened due to time out.  Please try again in a moment."
            Case SE_ERR_DLLNOTFOUND
                lErr = 48: sErr = "The specified dynamic-link library was not found."
            Case SE_ERR_FNF
                lErr = 53: sErr = "File not found"
            Case SE_ERR_NOASSOC
                sErr = "No application is associated with this file type."
            Case SE_ERR_OOM
                lErr = 7: sErr = "Out of memory"
            Case SE_ERR_PNF
                lErr = 76: sErr = "Path not found"
            Case SE_ERR_SHARE
                lErr = 75: sErr = "A sharing violation occurred."
            Case Else
                sErr = "An error occurred occurred whilst trying to open or print the selected file."
            End Select
                    
            Err.Raise lErr, , App.EXEName & ".GShell" & vbLf & sErr
            ApriAllegato = False
        End If
    
    End Function
    Signori si nasce! E io modestamente, lo nacqui!!!
    Totò

  7. #7
    Utente di HTML.it L'avatar di gibra
    Registrato dal
    Apr 2008
    residenza
    Italy
    Messaggi
    4,244
    In base alla dichiarazione, questa istruzione non va bene:
    lR = ShellExecute(Owner, sOperation, sFile, 0, 0, essSW_SHOWNORMAL)

    dovrebbe essere
    lR = ShellExecute(Owner, sOperation, sFile, "", "", essSW_SHOWNORMAL)

    Comunque a me funziona anche la prima.


    E' difficile correggere un errore che non si verifica sul proprio PC.

    Prova a reinstallare Acrobat.
    Non saprei cos'altro consigliarti.


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.