-3

Can someone please tell me how to open an executable with my vb.net project. For now I have the code for the user selecting the executable from a dialog:

    Dim openFileDialog1 As New OpenFileDialog()
    openFileDialog1.Filter = "Executable Files|*.exe"
    openFileDialog1.Title = "Select an Executable File"

    If openFileDialog1.ShowDialog() = DialogResult.OK Then
        Me.Cursor = New Cursor(openFileDialog1.OpenFile())
    End If
HDFA
  • 1
  • 4
  • 1
    Possible duplicate of [Click a button --> Launch a \*.exe file](http://stackoverflow.com/questions/2631223/click-a-button-launch-a-exe-file) – Nik Bo Feb 14 '16 at 09:45
  • 1
    You need to be a bit more specific here. »Opening an executable« usually means executing it, which you can do with `Process.Start`. However, your code looks like you're trying to use the executable as your mouse pointer (?). Since executables are not cursor files this is unlikely to work out well. They may have cursors (or icons, which are similar, but lack the hotspot) _embedded_ into the executable, which you could use, but then you're asking about extracting a resource from an executable and using that as a cursor. – Joey Feb 14 '16 at 09:47
  • Yeah what I wanted to do was after having the executable opened, have its icon replace the current icon of the picturebox which is what was used to open the dialog – HDFA Feb 14 '16 at 09:55

1 Answers1

1

You can use Icon.ExtractAssociatedIcon to extract an icon from an executable. You can then use its ToBitmap method to convert it into a bitmap that you can either assign to your PictureBox' Image property, or draw it using a graphics context.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • Could you please elaborate on how I should use this, I've tried to use this command line but I'm always getting different errors. – HDFA Feb 15 '16 at 09:02
  • `Icon` is a .NET class with a method `ExtractAssociatedIcon`. This has nothing to do with the command line, it's simply code you can write in VB.NET in your application. – Joey Feb 15 '16 at 09:59