Solved

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

Posted on 2000-05-17
3
148 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 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

14 Experts available now in Live!

Get 1:1 Help Now