Results 1 to 8 of 8

Thread: [Solved] Help with "Open with"

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    15

    Resolved [Solved] Help with "Open with"

    I'm trying to make a videoplayer (with videolan activex component) in vb.net 2010 express, but i'm not sure about the open with.
    More exact: Right click some.some file, select open with (or make exe file default itself to open .some files) choose my program, program adds file path to text box.
    Please help me here.
    Last edited by rosaage; Dec 2nd, 2011 at 03:09 PM.

  2. #2
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    Re: Help with "Open with"

    You are quite impatient. As for the open With, I'm not so sure how best to set that. But when you have set that and you open a file It sends the path of file to your program and then it expects that your program knows what to do with it. It is called Command Line arguments. A search for that would turn up loads of info.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  3. #3
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help with "Open with"

    It took a little bit of googling but I came up with this:

    http://www.codeproject.com/KB/vb/VBFileAssociation.aspx


    vb.net Code:
    1. My.Computer.Registry.ClassesRoot.CreateSubKey(".hello").SetValue_
    2.     ("", "Hello", Microsoft.Win32.RegistryValueKind.String)
    3. My.Computer.Registry.ClassesRoot.CreateSubKey_
    4.     ("Hello\shell\open\command").SetValue("", Application.ExecutablePath & _
    5.     " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Help with "Open with"

    Do not bump your threads (especially after only 20 minutes)

    You are expecting people with the right knowledge for your problem to be online 24/7 (and have time to answer it as soon as they see it), which is not the case. We are all based in different time zones and participation is voluntary (no one is being paid to be here).

    People will read & reply when they get the chance. Your bump has been deleted.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    15

    Re: Help with "Open with"

    Hmm... I tried the web page, but doesen't solve my problem. I'm trying to move a file to the .exe (icon not form) and make so the program reads the path and put it in a textbox.
    and Hack sorry, didn't mean it like that. meant my had 0 views other posted after had 30 views. but Sorry.
    Never going to happen again.

  6. #6
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help with "Open with"

    Well, first we need to understand what happens when you drag a file onto an exe in windows. Really all it does is open the exe with the file as a command line argument.

    for example writing:

    Test.exe file.txt

    in the command line
    would be the same as dragging file.txt onto test.exe in windows explorer.

    so to get that data, you would first need to know what is contained in that command line argument:

    vb.net Code:
    1. If Environment.GetCommandLineArgs.Count > 1 Then
    2.             MsgBox(Environment.GetCommandLineArgs(1).ToString)
    3. End If

    This will check to see if your program was launched with an argument (argument 0 is always your program itself). And then it shows what it is by using a messagebox.

    I'm pretty sure setting a file association works the same way, so if you associate a file with your program it will still open using this code.
    Last edited by stepdragon; Dec 2nd, 2011 at 03:01 PM. Reason: I said more than I needed so I removed it.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    15

    Resolved Re: Help with "Open with"

    Quote Originally Posted by stepdragon View Post
    Well, first we need to understand what happens when you drag a file onto an exe in windows. Really all it does is open the exe with the file as a command line argument.

    for example writing:

    Test.exe file.txt

    in the command line
    would be the same as dragging file.txt onto test.exe in windows explorer.

    so to get that data, you would first need to know what is contained in that command line argument:

    vb.net Code:
    1. If Environment.GetCommandLineArgs.Count > 1 Then
    2.             MsgBox(Environment.GetCommandLineArgs(1).ToString)
    3. End If

    This will check to see if your program was launched with an argument (argument 0 is always your program itself). And then it shows what it is by using a messagebox.

    I'm pretty sure setting a file association works the same way, so if you associate a file with your program it will still open using this code.
    Thanks, your code did not work right but after a couple of tries i got this:
    Code:
            If Environment.GetCommandLineArgs.Count > 1 Then
                Dim filename As String = Environment.GetCommandLineArgs(1).ToString
                TextBox1.Text = filename
            End If
    And if i drag a movi to my .exe the path comes up in textbox1 YAY!

  8. #8
    Hyperactive Member stepdragon's Avatar
    Join Date
    Aug 2011
    Location
    Cincinnati
    Posts
    288

    Re: Help with "Open with"

    Quote Originally Posted by rosaage View Post
    after a couple of tries i got this:
    Code:
            If Environment.GetCommandLineArgs.Count > 1 Then
                Dim filename As String = Environment.GetCommandLineArgs(1).ToString
                TextBox1.Text = filename
            End If
    What I wrote was a proof of concept, it wasn't meant to work via copy and paste. That way you could adapt it to your needs. I'm glad it was of use.

    If you're wrong, you'll learn. If I'm wrong, I'll learn. Try something new and go from there. That's how we improve.

    CodeBank: VB.Net - Simple Proper Image Scaling in Correct Aspect Ratio - Star Rating Control
    Useful Links: HOW TO USE CODE TAGS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width