Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting process id for file opened with default program

Status
Not open for further replies.

dbrb2

Instructor
Jul 19, 2004
121
GB
Hi,

If I open a specific program, using the following:

Code:
Dim myProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start("calc.exe")

then I can access the pid for that process using myProcess.id, and use it to manipulate the process.

If however I just specify a file or URL I want to open:
Code:
Dim myProcess As System.Diagnostics.Process = System.Diagnostics.Process.Start("someDoc.doc")

Then although the file / URL is handled by the default application and opens perfectly, I do not get a pid returned.

Is there any way around this, such that I can use the ddefault progam but still get a pid, or am I stuck with explicitly stating the program to use each time?

Cheers
 
You have to start the program directly. What you are doing is allowing windows to open the default program which is sperate from your process call. For instance you would want to open Word with the command line options to open someDoc.doc. I don't remember what the command line options for Word is, but if you do a Google search you should find them.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Ummm....basicly that says no, but let me say directly no you can't do it and allow it to still use the default program.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
How annoying. I guess I could do it by assuming that immediately after I have launched the file in question, whatever program was used to launch it will have focus, and get the pid of the active window... it seems a bit messy though :)
 

I ran the following code:

OpenFileDialog1.ShowDialog()

Dim ThisProcess As Process = System.Diagnostics.Process.Start(OpenFileDialog1.FileName)

MsgBox(ThisProcess.Id)

I got a process ID every time. I tested it with .doc, .pdf, .xls, .txt, .gif, .jpg and a few other file types.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Yes, you are right. The problem appears to centre around a file type where the default program is already running, and merely opens another file.

For example, if I use the above code to open an xml file, it loads in internet explorer and gives me a pid.

If I run the same code again, the xml file loads in a new tab of internet explorer, and there is no new pid.

With URLS, the browser loads the page fine, but no pid is returned. This is not too bad, as I ca nmake this a special case.

I wonder if I could use VB to get the default programs for each file type I present it with, and handle the program launching myself...
 
I have fixed it by using some code I found online that finds the default program for a given filetype, and then calling the program explicitly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top