0

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.

Konamiman
  • 49,681
  • 17
  • 108
  • 138
Emerald
  • 864
  • 1
  • 14
  • 37
  • If its a Windows.Forms App, process.start with a FULL URL, may open the default browser (Ex: process.start("http://stackoverflow.com") – Morcilla de Arroz Oct 22 '15 at 06:59
  • Yes it can open my website url if using `Process.Start()` BUT it cannot run my `.exe` file – Emerald Oct 22 '15 at 07:02
  • Ah! do you mean that URLs are OK but the issue it's with EXE. Ok, its a WinForms app? Why don't you check the path before (io.file.exists)? Are any parameters needed? Are permissions granted? Did you check the returned values of Shell or Process,Start? – Morcilla de Arroz Oct 22 '15 at 07:08
  • I am using Windows Form App. I already check all my `.exe` path and my website url. All are correct. – Emerald Oct 22 '15 at 07:16
  • Check with notepad.exe. If works, something in your exe may be – Morcilla de Arroz Oct 22 '15 at 07:17
  • I'm not sure either it needs any parameter but IF I use `Shell()` function all my `.exe` files can run BUT not working for website url :( – Emerald Oct 22 '15 at 07:18
  • It's working if I use `notepad.exe`. Too bad. I cannot figure out why because my `.exe` files are all doing fine. Nothing wrong with the path also. All are correct. – Emerald Oct 22 '15 at 07:22
  • can you post your exe file path as you pass it to shell method? – fofik Oct 22 '15 at 10:48
  • Hi @fofik , my exe file path is inside the XML file and I store it using array so when I shell() it I do like this `Shell(MenuListBox(i, j, 1))`. But since `Process.Start()` is the suitable method to run both .exe and website url so I used it instead of `Shell()`. My program is completed already with the `Process.Start()` :) – Emerald Oct 22 '15 at 13:59

3 Answers3

1

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

Community
  • 1
  • 1
fofik
  • 998
  • 11
  • 17
0

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.

Morcilla de Arroz
  • 2,104
  • 22
  • 29
  • `An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll Additional information: The system cannot find the file specified` Here is the error that appear if I use `Process.Start()` to run `.exe` file – Emerald Oct 22 '15 at 07:45
  • If the file is there and you can open it outside the app > permissions. As I say, place it in a granted location, an tell me the result. Or try to run your app as an Administrator, etc. – Morcilla de Arroz Oct 22 '15 at 07:58
0

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 :)

Emerald
  • 864
  • 1
  • 14
  • 37