Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Shell ("start " & filename) command does not work on NT

Hi

I am unable to use the shell("start filename) command in VB when running on NT. The file which needs to run is an .html file. This however works on windows 98. The shell commandshell("c\winnt\notepad.exe") however works fine on NT as well as win 98.
Basically I need to run an HTML file on clicking of a button in a VB program. How do I do it

Please help

Regards,
KC
0
explorer007
Asked:
explorer007
1 Solution
 
calacucciaCommented:
I think you have to specify application and file to be started. FOr example:

Dim Retval
Retval = Shell("C:\Windows\Write.exe D:\EE_Temporary_Trials\Log_IPF.txt")

where C:\Windows\Write.exe is the application Write/WordPad and Log_IPF.txt is the file to be opened with this application.

Depending on which application you want to use to open the .html file, you need to specify its location.

For example:

Dim Retval
Retval = Shell("C:\Program Files\Internet Explorer\Iexplore.exe C:\MyDir\MyFile.html")

Good Luck
Calacuccia
0
 
VbmasterCommented:
I think it's RUN instead of START in NT. But I would recommend you to use the ShellExecute API instead, it will automatically look what the associated program is and execute it.

Using code like this will work...

  If (Run(htmlfilename) = "") Then
    Call Msgbox("File successfully executed")
  Else
    Call Msgbox("The associated program could not be executed")
  End If


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

Function Run(strFilePath As String, Optional strParms As String, Optional strDir As String) As String
       
  Const SW_SHOW = 5
 
  'Run the Program and Evaluate errors
  Select Case ShellExecute(0, "Open", strFilePath, strParms, strDir, SW_SHOW)
  Case 0
    Run = "Insufficent system memory or corrupt program file"
  Case 2
    Run = "File not found"
  Case 3
    Run = "Invalid path"
  Case 5
    Run = "Sharing or Protection Error"
  Case 6
    Run = "Seperate data segments are required for each task"
  Case 8
    Run = "Insufficient memory to run the program"
  Case 10
    Run = "Incorrect Windows version"
  Case 11
    Run = "Invalid program file"
  Case 12
    Run = "Program file requires a different operating system"
  Case 13
    Run = "Program requires MS-DOS 4.0"
  Case 14
    Run = "Unknown program file type"
  Case 15
    Run = "Windows program does not support protected memory mode"
  Case 16
    Run = "Invalid use of data segments when loading a second instance of a program"
  Case 19
    Run = "Attempt to run a compressed program file"
  Case 20
    Run = "Invalid dynamic link library"
  Case 21
    Run = "Program requires Windows 32-bit extensions"
  Case Else
    Run = ""
  End Select

End Function
0
 
GivenRandyCommented:
Try the following approach instead:

To open an HTM file in a browser (or to call any file with a file association already defined):
---
ShellExecute Me.hwnd, "open", "yourfile.htm", "", "", SW_SHOWNORMAL
---

Put this section in your module area:

---
Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_NORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Const SW_MAXIMIZE = 3
Const SW_SHOWNOACTIVATE = 4
Const SW_SHOW = 5
Const SW_MINIMIZE = 6
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_RESTORE = 9
Const SW_SHOWDEFAULT = 10
Const SW_MAX = 10

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
---
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now