Emerald
Emerald

Reputation: 874

Shell() website url

Is it possible to run website url using Shell() command? I saw someone post

Shell() can only read the executable path

But regarding to this site http://www.vb6.us/forums/general-questions/attaching-website-links-your-command-button Shell() can used to run the website url.

I have some website url inside my XML file and I tried to run them using Shell() command as my XML file also containing .exe file path. So I am running those .exe file and website url like this

Dim i As Integer, j As Integer

For i = 0 To 9
    For j = 0 To 9
        If MenuListBox.SelectedItem = MenuListBox(i, j, 0) Then

            Shell(MenuListBox(i, j, 1))

        End If
    Next
Next

I am using array to store each of elements inside my XML file.

So the problem here is, I can only run my .exe files and when running website url it said that

File not found

Even though my path is correct. I did used the Process.Start() also but it only working for the website url, not the .exe file. It returns me this error.

The system cannot find the file specified

Kindly to help me. Thanks in advance.

Upvotes: 0

Views: 1164

Answers (3)

Emerald
Emerald

Reputation: 874

Thanks to @Capitán Cavernícola for your suggestion.

If path.toupper like "*.EXE"  
  shell path
Else 
  process.start (path)
End if 

I took your code and change the path.toupper like "*.EXE" to Path.Contains(".exe") Then

Here is my coding that working all fine now.

Dim Path As String = MenuListBox(i, j, 1)

                    If Path.Contains(".exe") Then
                        Shell(Path)
                    Else
                        Process.Start(Path)
                    End If

Thank you all :)

Upvotes: 0

Morcilla de Arroz
Morcilla de Arroz

Reputation: 2182

Quick solution, to get time to check the real solution:

If path.toupper like "*.EXE"  
  shell path
Else 
  process.start (path)
End if 

But if you have a Win32Exception (show us the full message) ... they used to appear on 32/64 bits issue. etc. But, as Shell is working, I think you have a Credentials issue= permissions of that folder/exe.

Place that exe on another granted location to test.

Upvotes: 0

fofik
fofik

Reputation: 1008

Process.Start() can be used for url and executables and other files. If you pass a path to a file, like a doc file, it is open with default application. In your case if you pass a url like "http://www.google.com" it will be opened with your default browser.

According to MSDN:

Starting a process by specifying its file name is similar to typing the information in the Run dialog box of the Windows Start menu. Therefore, the file name does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system. For example the file name can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated.doc files with a word processing tool, such as Microsoft Word. Similarly, in the same way that the Run dialog box can accept an executable file name with or without the .exe extension, the .exe extension is optional in the fileName parameter. For example, you can set the fileName parameter to either "Notepad.exe" or "Notepad".

opening a url here and here

Upvotes: 1

Related Questions