I have question about shell command

well lets say i have this

Shell("\bin\game.exe", AppWinStyle.NormalNoFocus)

Well as you know the command will come up an say File Not Found

FileNotFoundException

So how can i put this command and when the file is not found turn up with this method

MessageBox.Show("File not found.Please place the program into the program folder")'

Without showing the filenotfound exception

Hope you understand

MarkGia

Dani AI

Generated

A concise, robust approach is to build an unambiguous path to the executable, verify the file exists, then start it. That avoids parsing exception text (which suggested) and prevents the runtime error that encountered when the launcher couldn't find an exe in a relative folder.

Dim exePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin", "game.exe")

If System.IO.File.Exists(exePath) Then
    Dim psi As New System.Diagnostics.ProcessStartInfo(exePath) With {
        .UseShellExecute = True,
        .WorkingDirectory = System.IO.Path.GetDirectoryName(exePath)
    }
    System.Diagnostics.Process.Start(psi)
Else
    MessageBox.Show("Executable not found in the expected bin folder.")
End If

Notes and troubleshooting

  • A leading slash makes the path root-based; prefer Path.Combine with AppDomain.CurrentDomain.BaseDirectory or Application.StartupPath so the application folder is used reliably.
  • Comparing exception message text is brittle (locale and runtime differences). Either pre-check with File.Exists or catch specific exception types (Win32Exception, UnauthorizedAccessException) and handle them.
  • If the exe is part of the project, set its "Copy to Output Directory" to "Copy always" or "Copy if newer" so it lands in the build output where the app expects it.
  • If Process.Start still fails, check WorkingDirectory, permissions, and whether the process requires an associated handler (UseShellExecute toggles that behavior).

This addresses the original symptom by removing ambiguity about the path and giving a clear, user-friendly fallback instead of relying on raw runtime error text.

Recommended Answers

All 3 Replies

Well masters i dont think it is difficult to tell me that it is a two minutes answer

Using the Try - Catch method.

Try 
Shell("\bin\game.exe", AppWinStyle.NormalNoFocus) 
catch ex as Exception 
if ex.message = "" 'Can't remember the exact text, type in the exact exception message
then MessageBox.Show("File not found.Please place the program into the program folder")
else 
msgbox (ex.message) 
end if
end try

o yeah thanks man

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.