Shortcut "Start In"

Miro

Member
Joined
May 9, 2006
Messages
6
Programming Experience
3-5
Sorry I am unsure if i should be posting this in "General Discussion".
I am a bit new to vb.net ( 2003 ) but still, i am stuck.

Example: A user uses the same EXE file ( of another app ) to open up
multiple versions of an exe.
In each shortcut the "Start In" portion of the shortcut is different - for each data dir.

I am using the
myProc = Process.GetProcessesByName("anApplicationProcess")

I can find in the myProc variable where the exe file is stored, / path.
But I cannot find out how to access the "Start In" of a process.

I am going to be killing processes based on a certain "Start In" path.
using :
ForEach myProcess In myProc
myProcess.Kill()
Next
So I need to get the "Start In" portion from the Process info. Is there any
way to get this? Otherwise I will be killing an app running in a different data dir that I do not want to kill.

Thanks,
Miro
 
Process.StartInfo.WorkingDirectory - would be, but it's only for process you start with Process.Start, else this information is not stored/preserved.
 
Last edited:
Start Info is empty

Here is a simple example i created and Its empty for me.
I let vb compile it, and then made a shortcut to the exe with a
"Start In" of C:\Temp and the txtOther is empty.
Is my code correct ? I did this in the Form.Load

myProcesses = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
txtOther.Text = myProcesses(0).StartInfo.WorkingDirectory()

Thanks
Miro
 
yea but GetProcesses.. does a fetch where PI isn't stored anymore, sorry about that, Miro, you won't get it. The docs sounds to me that the Get part of this property is only relevant when you start some processes yourself and later want check back on these instances.
 
Working Directory

So I have tried this then:
I wrote a program, to call itself and set up the working directory.
By calling itself i look at the process and it is still blank.

I think I am setting it correctly here. Funny that the call wouldnt recognize it? I would have expected it to, since I am setting it.

Funny why the processes would have that there, but not retain the info.


VB.NET:
Form Load
Dim myProcesses() As Process
Dim myProcess As Process
Dim myArgs() AsString

txtArgs.Text = System.Environment.CommandLine()
txtPath.Text = System.Environment.CurrentDirectory()
myProcesses = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
txtOther.Text = myProcesses(0).StartInfo.WorkingDirectory()
--------------------

On a Button Click -> Call a program and set up StartInfo


VB.NET:
Dim StartInfo AsNew ProcessStartInfo()
Dim myProcesses() As System.Diagnostics.Process
Dim myNewApp AsNew Process()
myNewApp.StartInfo.FileName = txtArgs.Text ' example: "Notepad.exe"
myNewApp.StartInfo.WorkingDirectory = txtOther.Text 'Example: "c:\bla"
myNewApp.StartInfo.WindowStyle = ProcessWindowStyle.Normal
myNewApp.Start()
myProcesses = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName)
'Place a debuger on next line
MessageBox.Show("Prog Keeps Running", "Keeps Running", _
MessageBoxButtons.OK, MessageBoxIcon.Asterisk)


------------
 
Last edited by a moderator:
You can't ask operating system for some processes and check their startinfo.workingdirectory because operating system don't keep track of this information.

If you started a lot of same processes but from different workingdirs you could store an array of all those processes you started and query it for information, you could keep track of event Exited for each process and also check that instance here for workingdir.
 
Thank you John H.

I think that is what I will do.

I was under the impression that every property of a processes actually comes from windows, not vb.net

Thanks again for the timely responses as well.

Miro
 
Back
Top