Home All Groups Group Topic Archive Search About

ShellExecute in VB2005

Author
17 Jan 2006 7:38 PM
Jedi10180
Does ShellExecute work in VB2005? I am trying to open a pdf with a button - I
get no errors, but nothing is happening. Here is my code:
Option Explicit On

Public Class frmPROTest
    Const SW_SHOWNORMAL = 1
    Dim hwnd

    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 Sub PDF_Click()

        Call ShellExecute(Me.hwnd, "open", "S:\Users\JJolly\PRO
CD\pdf\english\ESY Book.pdf", "", 0, SW_SHOWNORMAL)

    End Sub

End Class

Thanks for any help.

Author
17 Jan 2006 7:46 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"Jedi10180" <Jedi10***@discussions.microsoft.com> schrieb:
> Does ShellExecute work in VB2005? I am trying to open a pdf with a
> button - I
> get no errors, but nothing is happening. Here is my code:
> Option Explicit On
>
> Public Class frmPROTest
>    Const SW_SHOWNORMAL = 1
>    Dim hwnd
>
>    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

Your declarations are wrong.  Instead of fixing them, I suggest to use
'System.Diagnostics.Process.Start' instead of 'ShellExecute'.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
17 Jan 2006 8:08 PM
Jedi10180
I have also tried 'System.Diagnostics.Process.Start', but apparently my
declarations are wrong when I try it too because nothing happens at all. Can
you just give a short code snippet that would include everything I need to
open a pdf file using 'System.Diagnostics.Process.Start'?
Also, we want this program to be run directly from a CD with no installation
- how do I go about doing that?
Thanks.

Show quoteHide quote
"Herfried K. Wagner [MVP]" wrote:

> "Jedi10180" <Jedi10***@discussions.microsoft.com> schrieb:
> > Does ShellExecute work in VB2005? I am trying to open a pdf with a
> > button - I
> > get no errors, but nothing is happening. Here is my code:
> > Option Explicit On
> >
> > Public Class frmPROTest
> >    Const SW_SHOWNORMAL = 1
> >    Dim hwnd
> >
> >    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
>
> Your declarations are wrong.  Instead of fixing them, I suggest to use
> 'System.Diagnostics.Process.Start' instead of 'ShellExecute'.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
>
Author
17 Jan 2006 9:21 PM
Kerry Moorman
Jedi10180,

Programs written in a .Net language require the .Net framework to be
installed in order to execute the program.

Kerry Moorman


Show quoteHide quote
"Jedi10180" wrote:

> Also, we want this program to be run directly from a CD with no installation
> - how do I go about doing that?
> Thanks.
>
Author
17 Jan 2006 7:49 PM
Oenone
Jedi10180 wrote:
> Does ShellExecute work in VB2005? I am trying to open a pdf with a
> button - I get no errors, but nothing is happening.

Have you considered the following method using the .NET framework?

\\\
    Dim proc As New Process

    With proc.StartInfo
        .FileName = "S:\Users\JJolly\PRO CD\pdf\english\ESY Book.pdf"
        .UseShellExecute = True
        .Verb = "open"
    End With

    'Launch the file
    proc.Start()
///

--

(O)enone
Author
17 Jan 2006 9:16 PM
Philip Wagenaar
why doesn't cmd.exe with arguments /c copy c:\file.txt d:\directory work with
the process start?

Show quoteHide quote
"Oenone" wrote:

> Jedi10180 wrote:
> > Does ShellExecute work in VB2005? I am trying to open a pdf with a
> > button - I get no errors, but nothing is happening.
>
> Have you considered the following method using the .NET framework?
>
> \\\
>     Dim proc As New Process
>
>     With proc.StartInfo
>         .FileName = "S:\Users\JJolly\PRO CD\pdf\english\ESY Book.pdf"
>         .UseShellExecute = True
>         .Verb = "open"
>     End With
>
>     'Launch the file
>     proc.Start()
> ///
>
> --
>
> (O)enone
>
>
>