Results 1 to 9 of 9

Thread: unknown shell

  1. #1

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    unknown shell

    Hi

    i have made a help file for my program in html, so the file is an html file, the files will be inlcuded in my package for my program, but i don't know where the program will be installed to, so i don't think i can make a normal shell command, what i need is a command that will open this file (index.html) from the directory that the program is in when the button is pressed, if this makes any sense, please help, if it doesn't then i will try again

    thanks for any help

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    App.Path will return the path the .EXE is in during runtime. So you can do something like

    Shell "START "+App.Path+"\myhelp.html"
    Last edited by Buzby; Jul 9th, 2001 at 06:05 AM.
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Try using ShellExecute :

    Code:
    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
    Public Const SW_SHOWNORMAL = 1
    
    Private Sub Command1_Click()
        Dim l As Long
        l = ShellExecute(Me.hwnd, "Open", App.Path & "\index.html", "", "C:\", SW_SHOWNORMAL)
    End Sub
    -= a peet post =-

  4. #4

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604
    cheers guys

    Buzby - your just came up with file not found, not sure why because it was there.

    Peet - cheers yours worked well, though i needed to make the declarations private

    Thanks for your help guys

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    The Shell function will only execute programs, while the ShellExecute function will launch a file with its default application.
    -= a peet post =-

  6. #6

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604
    that would explain why i was having fun with the shell command,

    thanks for your help again

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  8. #8
    Note that if a file is not found with ShellExecute, there is no way that I know of to detect that. It just executes ShellExecute, and nothing happens.

  9. #9
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    filburt1

    you have to check the value returned when executing shellexecute ...

    try this :
    Code:
    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
    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&
    
    Private Sub Command1_Click()
        Dim l As Long
        Dim msg As String
        l = ShellExecute(Me.hwnd, "Open", App.Path & "\index.html", "", "C:\", SW_SHOWNORMAL)
    
              If l <= 32 Then
                  'There was an error
                  Select Case l
                      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
    -= a peet post =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width