Newsgroup: it.comp.lang.visual-basic
Titolo: Server per .doc (Word), per .exe (Excel), .........

Buona giornata a tutta la lista.
Dovrei lanciare una "Shell" per eseguire un file non eseguibile (per esempio
".doc"), in cui all'interno del registro di Windows è associato Winword.
Come faccio a risalire da un ".doc", alla locazione in cui è installato su
quella macchina Winword?
In definitiva:
    x = Shell("c:\documenti\pippo.doc", vbMaximizedFocus)
non funziona. Ci vorrebbe:
    x = Shell (locazione_di_word "c:\documenti\pippo.doc", vbMaximizedFocus)
Grazie a chi vorrà rispondermi!
Alberto

...


Interessante la tua soluzione...
Purtroppo però, non mi serve solo per Winword, ma per qualsiasi file
associato.
Il problema sussiste ancora pertanto.
Se qualche buon'anima ha un altro suggerimento...
Grazie comunque per il suggerimento
Alberto

E' giusto, ma c'e' un'altra soluzione piu' generale che vale qualunque
sia il tipo di file (purche' associato a qualcosa).
' in un modulo .bas:
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
Public Const SW_SHOW = 1
Public Sub lavora(frm As Form, _
                  ByVal quelchevuoi As String)
    Dim h As Long
    h = ShellExecute(frm.hwnd, "open", quelchevuoi, "", "", SW_SHOW)
End Sub
'esempio di uso
Questo esempio serve a lanciare il browser che hai associato ai file
.htm e gli fa aprire il file sottoindicato
    p = App.Path & "\tuofile.htm"
    Call lavora(Me, p)
Provato con netscape: la seconda volta che lo chiami ti fa vedere il
secondo .htm, NON ti lancia una seconda istanza di netscape. Grande!
Ciao
gs


 wrote in message
389AB374...@chifis.unipv.it...


Puoi provare con l'API ShellExecute()
... ti invio un articolo che ho trovato sull'MSDN library
spero che ti sia utile
Ruggero
HOWTO: Use ShellExecute to Launch Associated File (32-bit)
ID: Q170918
--------------------------------------------------------------------------------
The information in this article applies to:
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for
Windows, version 6.0
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise
Editions for Windows, version 5.0
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit
only, for Windows, version 4.0
--------------------------------------------------------------------------------
SUMMARY
You can use the Windows API ShellExecute() function to start the application
associated with a given document extension without knowing the name of the
associated application. For example, you could start the Paintbrush program by
passing the filename ARCADE.BMP to the ShellExecute() function.
MORE INFORMATION
The ShellExecute function opens or prints the specified file. Following is the
declaration to use when calling this function from Visual Basic:
   Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                   (ByVal hwnd As Long, ByVal lpszOp As String, _
                    ByVal lpszFile As String, ByVal lpszParams As String, _
                    ByVal LpszDir As String, ByVal FsShowCmd As Long) _
                    As Long
The following table provides descriptions for each parameter:
Parameter     Description
----------------------------------------------------------------------------
hwnd          Identifies the parent window. This window receives any
              message boxes an application produces (for example, for error
              reporting).
lpszOp        Points to a null-terminated string specifying the operation
              to perform. This string can be "open" or "print." If this
              parameter is NULL, "open" is the default value.
lpszFile      Points to a null-terminated string specifying the file
              to open.
lpszParams    Points to a null-terminated string specifying parameters
              passed to the application when the lpszFile parameter
              specifies an executable file. If lpszFile points to a string
              specifying a document file, this parameter is NULL.
LpszDir       Points to a null-terminated string specifying the default
              directory.
FsShowCmd     Specifies whether the application window is to be shown when
              the application is opened.
Step-by-Step Example
The following example demonstrates how to start an application or load a
document into its associated application. The Windows API ShellExecute()
function is different from the Visual Basic Shell() function in that you can
pass the ShellExecute() function the name of a document and it will launch the
associated application, and then pass the filename to the application.
Start a New project in Visual Basic. Form1 is created by default.
Add the following code to the General Declarations section of Form1:
      Option Explicit
      Private Declare Function ShellExecute Lib "shell32.dll" Alias _
      "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
      String, ByVal lpszFile As String, ByVal lpszParams As String, _
      ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
      Private Declare Function GetDesktopWindow Lib "user32" () As Long
      Const SW_SHOWNORMAL = 1
      Const SE_ERR_FNF = 2&
      Const SE_ERR_PNF = 3&
      Const SE_ERR_ACCESSDENIED = 5&
      Const SE_ERR_OOM = 8&
      Const SE_ERR_DLLNOTFOUND = 32&
      Const SE_ERR_SHARE = 26&
      Const SE_ERR_ASSOCINCOMPLETE = 27&
      Const SE_ERR_DDETIMEOUT = 28&
      Const SE_ERR_DDEFAIL = 29&
      Const SE_ERR_DDEBUSY = 30&
      Const SE_ERR_NOASSOC = 31&
      Const ERROR_BAD_FORMAT = 11&
      Function StartDoc(DocName As String) As Long
          Dim Scr_hDC As Long
          Scr_hDC = GetDesktopWindow()
          StartDoc = ShellExecute(Scr_hDC, "Open", DocName, _
          "", "C:\", SW_SHOWNORMAL)
      End Function
      Private Sub Form_Click()
          Dim r As Long, msg As String
          r = StartDoc("C:\WINDOWS\ARCADE.BMP")
          If r <= 32 Then
              'There was an error
              Select Case r
                  Case SE_ERR_FNF
                      msg = "File not found"
                  Case SE_ERR_PNF
                      msg = "Path not found"
                  Case SE_ERR_ACCESSDENIED
                      msg = "Access denied"
                  Case SE_ERR_OOM
                      msg = "Out of memory"
                  Case SE_ERR_DLLNOTFOUND
                      msg = "DLL not found"
                  Case SE_ERR_SHARE
                      msg = "A sharing violation occurred"
                  Case SE_ERR_ASSOCINCOMPLETE
                      msg = "Incomplete or invalid file association"
                  Case SE_ERR_DDETIMEOUT
                      msg = "DDE Time out"
                  Case SE_ERR_DDEFAIL
                      msg = "DDE transaction failed"
                  Case SE_ERR_DDEBUSY
                      msg = "DDE busy"
                  Case SE_ERR_NOASSOC
                      msg = "No association for file extension"
                  Case ERROR_BAD_FORMAT
                      msg = "Invalid EXE file or error in EXE image"
                  Case Else
                      msg = "Unknown error"
              End Select
              MsgBox msg
          End If
      End Sub
Run the project and click the form.
General Information About the Process
If the function succeeds, the return value is the instance handle of the
application that was run. If there was an error, the return value is less than
or equal to 32.
The file specified by the lpszFile parameter can be a document file or an
executable file. If it is a document file, this function opens or prints it
depending on the value of the lpszOp parameter. If it is an executable file,
this function opens it even if the lpszOp specifies "PRINT."
REFERENCES
"Programmer's Reference, Volume 2: Functions" of the Microsoft Windows Software
Development Kit (SDK), pages 901-904
Additional query words: kbVBp500 kbVBp600 kbVBp kbdsd kbDSupport kbVBp400
KBWIN32SDK KBAPI
Keywords          :
Version           : WINDOWS:4.0,5.0,6.0
Platform          : WINDOWS
Issue type        :
Last Reviewed: May 12, 1999
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.


Non e' farina del mio sacco. L'ho avuto dal NG (non ricordo piu' chi, ma
lo ringrazio ancora adesso) qualche mese fa.
Potenza del NG.
Ciao
