|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Killing a Process if no App.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 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. -- Show quoteHide quoteDennis 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 > > > 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 Show quoteHide quote "Dennis" <Den***@discussions.microsoft.com> wrote in message news:15DAFB86-E1C0-4A18-A45A-ADE5AF86E6D5@microsoft.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 >> >> >> 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. Show quoteHide quote "Miro" <miron***@golden.net> wrote in message news:OUKhtResGHA.4140@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" <Den***@discussions.microsoft.com> wrote in message > news:15DAFB86-E1C0-4A18-A45A-ADE5AF86E6D5@microsoft.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 >>> >>> >>> > > 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 -- Show quoteHide quoteDennis 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" <miron***@golden.net> wrote in message > news:OUKhtResGHA.4140@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" <Den***@discussions.microsoft.com> wrote in message > > news:15DAFB86-E1C0-4A18-A45A-ADE5AF86E6D5@microsoft.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 > >>> > >>> > >>> > > > > > > >
how to make my own classes show their methods and/or variables while typing?
how to send null value to an Integer type variable? SendKeys problem when using Non-English Windows keyboard layouts Simple SELECT CASE Question Copy of class instance loop thru list of functions? Ping subnet Creating custom command line switches? Type validation VB.NET Winsock Multithreading question. |
|||||||||||||||||||||||