-
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
-
App.Path will return the path the .EXE is in during runtime. So you can do something like
Shell "START "+App.Path+"\myhelp.html"
-
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
-
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 :)
-
The Shell function will only execute programs, while the ShellExecute function will launch a file with its default application.
-
that would explain why i was having fun with the shell command,
thanks for your help again :)
-
-
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.
-
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
:)