|
-
Dec 2nd, 2011, 01:00 PM
#1
Thread Starter
New Member
[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.
-
Dec 2nd, 2011, 01:26 PM
#2
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.
-
Dec 2nd, 2011, 01:43 PM
#3
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:
My.Computer.Registry.ClassesRoot.CreateSubKey(".hello").SetValue_
("", "Hello", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey_
("Hello\shell\open\command").SetValue("", Application.ExecutablePath & _
" ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
-
Dec 2nd, 2011, 02:00 PM
#4
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.
-
Dec 2nd, 2011, 02:34 PM
#5
Thread Starter
New Member
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.
-
Dec 2nd, 2011, 02:52 PM
#6
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:
If Environment.GetCommandLineArgs.Count > 1 Then MsgBox(Environment.GetCommandLineArgs(1).ToString) 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.
-
Dec 2nd, 2011, 03:07 PM
#7
Thread Starter
New Member
Re: Help with "Open with"
 Originally Posted by stepdragon
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:
If Environment.GetCommandLineArgs.Count > 1 Then
MsgBox(Environment.GetCommandLineArgs(1).ToString)
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!
-
Dec 2nd, 2011, 03:14 PM
#8
Re: Help with "Open with"
 Originally Posted by rosaage
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|