Solved

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

Posted on 2000-05-17
3
145 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now