By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,238 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,238 IT Pros & Developers. It's quick & easy.

Killing a Process if no App.

P: n/a
I'm using VB.Net 2003

I have code - it works great - to kill a process(s) if they are running.
----
Dim myProcesses() As Process 'Funny - withouth the () in the
myProcesses it does not work
Dim myProcess As Process

myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text))
For Each myProcess In myProcesses
myProcess.Kill()
Next

Close() 'Program stops running after it is run.
----

The user has a program that runs, but when the program loads, sometimes it
loads in the
"Processes" tab, but not in the Application tab ( of the Windows Task
Manager ). This program
loads up some files associated with it, and actaully Locks these files until
its killed. This program also
only allows you to run one instance of it.

So what I would like to do, is Get all the processes ( see above code ), and
see if there is an Application
running associated with it.
If there is not, then kill that process.
If there is an Application, then just set focus to it.

I cannot find help on this on the net.
Can someone point me in the right direction please.

Thanks,

Miro
Jul 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
The reason that you need the () after myprocesses is that it is used as an
array when getting all the names of the processes, i.e., GetProcessesByName
returns an array all processes with the name passed to the method.
--
Dennis in Houston
"Miro" wrote:
I'm using VB.Net 2003

I have code - it works great - to kill a process(s) if they are running.
----
Dim myProcesses() As Process 'Funny - withouth the () in the
myProcesses it does not work
Dim myProcess As Process

myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text))
For Each myProcess In myProcesses
myProcess.Kill()
Next

Close() 'Program stops running after it is run.
----

The user has a program that runs, but when the program loads, sometimes it
loads in the
"Processes" tab, but not in the Application tab ( of the Windows Task
Manager ). This program
loads up some files associated with it, and actaully Locks these files until
its killed. This program also
only allows you to run one instance of it.

So what I would like to do, is Get all the processes ( see above code ), and
see if there is an Application
running associated with it.
If there is not, then kill that process.
If there is an Application, then just set focus to it.

I cannot find help on this on the net.
Can someone point me in the right direction please.

Thanks,

Miro
Jul 27 '06 #2

P: n/a
Thanks that answers that little if part. I was gonna search for that later.
I originally got this example from a website ( im still learning vb ) and it
didnt have it.
So i couldnt figure out why i needed it and they didnt.

Does anyone know how to do the App and process thing?

Thanks again Dennis.

Miro

"Dennis" <De****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
The reason that you need the () after myprocesses is that it is used as an
array when getting all the names of the processes, i.e.,
GetProcessesByName
returns an array all processes with the name passed to the method.
--
Dennis in Houston
"Miro" wrote:
>I'm using VB.Net 2003

I have code - it works great - to kill a process(s) if they are running.
----
Dim myProcesses() As Process 'Funny - withouth the () in the
myProcesses it does not work
Dim myProcess As Process

myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text))
For Each myProcess In myProcesses
myProcess.Kill()
Next

Close() 'Program stops running after it is run.
----

The user has a program that runs, but when the program loads, sometimes
it
loads in the
"Processes" tab, but not in the Application tab ( of the Windows Task
Manager ). This program
loads up some files associated with it, and actaully Locks these files
until
its killed. This program also
only allows you to run one instance of it.

So what I would like to do, is Get all the processes ( see above code ),
and
see if there is an Application
running associated with it.
If there is not, then kill that process.
If there is an Application, then just set focus to it.

I cannot find help on this on the net.
Can someone point me in the right direction please.

Thanks,

Miro

Jul 28 '06 #3

P: n/a
Also one more question i just ran accross this.

What is the difference between:
Dim myProcesses() As Process
and
Dim myProcesses() As System.Diagnostics.Process

I find the System.Diagnostics works better because then i can do this:

If myProcesses.Length 0 Then

If I just declare it as a Process I cannot get the length of it.
"Miro" <mi******@golden.netwrote in message
news:OU**************@TK2MSFTNGP06.phx.gbl...
Thanks that answers that little if part. I was gonna search for that
later.
I originally got this example from a website ( im still learning vb ) and
it didnt have it.
So i couldnt figure out why i needed it and they didnt.

Does anyone know how to do the App and process thing?

Thanks again Dennis.

Miro

"Dennis" <De****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
>The reason that you need the () after myprocesses is that it is used as
an
array when getting all the names of the processes, i.e.,
GetProcessesByName
returns an array all processes with the name passed to the method.
--
Dennis in Houston
"Miro" wrote:
>>I'm using VB.Net 2003

I have code - it works great - to kill a process(s) if they are running.
----
Dim myProcesses() As Process 'Funny - withouth the () in the
myProcesses it does not work
Dim myProcess As Process

myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text))
For Each myProcess In myProcesses
myProcess.Kill()
Next

Close() 'Program stops running after it is run.
----

The user has a program that runs, but when the program loads, sometimes
it
loads in the
"Processes" tab, but not in the Application tab ( of the Windows Task
Manager ). This program
loads up some files associated with it, and actaully Locks these files
until
its killed. This program also
only allows you to run one instance of it.

So what I would like to do, is Get all the processes ( see above code ),
and
see if there is an Application
running associated with it.
If there is not, then kill that process.
If there is an Application, then just set focus to it.

I cannot find help on this on the net.
Can someone point me in the right direction please.

Thanks,

Miro


Jul 28 '06 #4

P: n/a
Both of the below work. The System.Diagnostics is just the namespace which
contains the Process Class and you are just using the fully qualifiec Class
Type Name when you dimension Process using the System.Diagnostics.

Dim myprocesses() As Process
If myprocesses.Length 0 Then
'do something
End If

Dim myProcesses() As System.Diagnostics.Process
If myprocesses.Length 0 Then
'do something
End If
--
Dennis in Houston
"Miro" wrote:
Also one more question i just ran accross this.

What is the difference between:
Dim myProcesses() As Process
and
Dim myProcesses() As System.Diagnostics.Process

I find the System.Diagnostics works better because then i can do this:

If myProcesses.Length 0 Then

If I just declare it as a Process I cannot get the length of it.
"Miro" <mi******@golden.netwrote in message
news:OU**************@TK2MSFTNGP06.phx.gbl...
Thanks that answers that little if part. I was gonna search for that
later.
I originally got this example from a website ( im still learning vb ) and
it didnt have it.
So i couldnt figure out why i needed it and they didnt.

Does anyone know how to do the App and process thing?

Thanks again Dennis.

Miro

"Dennis" <De****@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.com...
The reason that you need the () after myprocesses is that it is used as
an
array when getting all the names of the processes, i.e.,
GetProcessesByName
returns an array all processes with the name passed to the method.
--
Dennis in Houston
"Miro" wrote:

I'm using VB.Net 2003

I have code - it works great - to kill a process(s) if they are running.
----
Dim myProcesses() As Process 'Funny - withouth the () in the
myProcesses it does not work
Dim myProcess As Process

myProcesses = Process.GetProcessesByName(Trim(TextBox1.Text))
For Each myProcess In myProcesses
myProcess.Kill()
Next

Close() 'Program stops running after it is run.
----

The user has a program that runs, but when the program loads, sometimes
it
loads in the
"Processes" tab, but not in the Application tab ( of the Windows Task
Manager ). This program
loads up some files associated with it, and actaully Locks these files
until
its killed. This program also
only allows you to run one instance of it.

So what I would like to do, is Get all the processes ( see above code ),
and
see if there is an Application
running associated with it.
If there is not, then kill that process.
If there is an Application, then just set focus to it.

I cannot find help on this on the net.
Can someone point me in the right direction please.

Thanks,

Miro


Jul 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.