Solved

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

Posted on 2000-05-17
3
150 Views
Last Modified: 2010-05-02
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
Comment
Question by:explorer007
3 Comments
 
LVL 17

Accepted Solution

by:
calacuccia earned 30 total points
ID: 2817444
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
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2817450
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
 
LVL 9

Expert Comment

by:GivenRandy
ID: 2817463
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 60
Best way to parse out a json string in VB6? 10 226
vb6 connector to mongodb 2 122
Problem to With line 4 63
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question