|
-
Jun 8th, 2007, 09:16 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Hello,
Process.Start() works great, unless the file extension is unknown, as in Process.Start("c:\asdf.jjj"). The file exists, but .jjj is an unknown extension. So, how can I get my program to behave like Windows does, and ask the user to select a program, like in the attached pic.
Thanks
Last edited by 18experience; Mar 23rd, 2010 at 09:37 AM.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 09:22 AM
#2
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Process.Start will open in the Default viewer only.
If you want to open with a particular exe you can call like this
vb Code:
Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
'Format wrong.So Code edited
Please mark you thread resolved using the Thread Tools as shown
-
Jun 8th, 2007, 09:27 AM
#3
Thread Starter
Fanatic Member
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Thank you, but what can I do for unknown extensions? Is there another way besides Process.Start? I am writing a program that allow the user to "attach" any kind of file they choose to an item. Then, they will be able to double click on it, and have it handled by Windows as if they double clicked it from Windows Explorer. I could put a try/catch around it to prevent errors and tell them they don't have the file associated with anything. I could even let them choose a program and then use your suggestion, but I really would prefer for the user to be presented with what they are familiar with in Windows.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 09:28 AM
#4
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
I wrote a function that checks if windows has a default program for the give extension, here:
VB.Net Code:
Private Function CanBeOpened(ByVal extension As String) As Boolean
If Not extension.StartsWith(".") Then
extension = "." & extension
End If
Dim key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.ClassesRoot
For Each s As String In key.GetSubKeyNames
If extension.Equals(s, StringComparison.CurrentCultureIgnoreCase) Then
Dim foundKey As Microsoft.Win32.RegistryKey = key.OpenSubKey(s)
If foundKey.GetValue("").Equals(String.Empty) Then
Return False
Else
Return True
End If
End If
Next
Return False
End Function
If this function returns false, you can prompt the user to select an executable file. Then use process.Start() to start this executable and pass the file as a parameter.
-
Jun 8th, 2007, 09:32 AM
#5
Thread Starter
Fanatic Member
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Atheist,
Thanks. I guess you were posting while I was posting. As you can see from my post, I had the same idea. That's a pretty good solution, but I was hoping that I could get my program to open that Dialog that Windows does in that situation. Do you think there is a UnknownExtensionDialog or something, sort of like OpenFileDialog?
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 09:34 AM
#6
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Nice Code Atheist
Please mark you thread resolved using the Thread Tools as shown
-
Jun 8th, 2007, 09:36 AM
#7
Thread Starter
Fanatic Member
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Is there a OpenWithDialog or something. I am basically trying to get this (attached pic).
Last edited by 18experience; Mar 23rd, 2010 at 09:37 AM.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 09:43 AM
#8
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
I dont think you can get that particular windows dialog, but Im certain you could create one of your own. Just fetch all installed applications from the registry, put them in a list and let the user select one.
-
Jun 8th, 2007, 09:54 AM
#9
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
You can get the dialog you asked for with this:
Code:
Dim openWithPrInfo As ProcessStartInfo = New ProcessStartInfo("C:\WINDOWS\system32\rundll32.exe")
openWithPrInfo.Arguments = " C:\WINDOWS\system32\shell32.dll, OpenAs_RunDLL asdf.jjj" '2nd arg is the file in question
Process.Start(openWithPrInfo)
I am blindly asuming your Windir is in C:, checking this first won't be a bad idea.
-
Jun 8th, 2007, 09:56 AM
#10
Thread Starter
Fanatic Member
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Thanks. If you click Browse on that form, it just brings up an OpenFileDialog, with Program being the default extension. I think I will just use that.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 10:04 AM
#11
Thread Starter
Fanatic Member
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
Kick ass. Thanks, Half. Thats works great. But, about that checking the Windows Directory. Any ideas on how to do that? Is there a namespace?
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 10:11 AM
#12
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
I don't think there is, but who knows / never bothered to really search for in the framework.
I always use an API for that
Code:
<System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto, EntryPoint:="GetWindowsDirectory")> _
Private Shared Function GetWindowsDirectory(ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sBuff As String = " "c
Dim iRet As Integer
sBuff = sBuff.PadRight(255)
iRet = GetWindowsDirectory(sBuff, 255)
MessageBox.Show(sBuff.Substring(0, iRet)) 'C:\Windows
End Sub
-
Jun 8th, 2007, 10:15 AM
#13
Thread Starter
Fanatic Member
Re: [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
If I could rate you twice, I would. Thanks again. And thanks to all who helped arrive at the conclusion... that was pretty fast.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Jun 8th, 2007, 11:09 PM
#14
Re: [RESOLVED] [02/03] Process.Start("c:\asdf.jjj"), unknown file extension
I just found out that this functionality is already exposed through a property of the StartInfo class - the 'Error Dialog' one:
Code:
Dim openWithPrInfo As New ProcessStartInfo
openWithPrInfo.FileName = "c:\asdf.jjj"
openWithPrInfo.ErrorDialog = True
Process.Start(openWithPrInfo)
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
|