|
Hi,
first you could use
System.Diagnostics.Process.GetProcesses();
to enumerate all running processes. But closing them could be difficult because you have to distinguish between system processes and application processes. A better way is to get all top-level applications (like the task-manager) and close them. Have a look at this link http://www.neowin.net/forum/lofiversion/index.php/t369213.html[^].
Regards
Sebastian
|
|
|
|
|
{
Process[] processes = Process.GetProcessesByName("notepad");
foreach (Process process in processes)
{
process.Kill();
}
}
modified on Thursday, May 13, 2010 1:08 AM
|
|
|
|
|
Use Process.GetProcessByName().
Or If you want to play it more safely, use Process.GetProcessById() method. To obtain the PIDs for the processes you want to end, get a list of all the processes running on your system using Process.GetProcesses(). Then manually traverse the list and find the PID of the processes you want to end, and then end them from there.
[Edit]Have a look at the process class and find out what it can do.[^][/Edit]
BTW, please answer this time, what are you building, and do you work for some company?
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
Hi,
what you could do is to monitor all the processes started while your app is running (look at the System.Diagnostics-namespace). If your app closes you can send a close to all the processes (or just do a hard "end process").
Regards
Sebastian
|
|
|
|
|
can u just send me example codes?
|
|
|
|
|
|
Now its working fine....
now everything is getting closed..but am getting the shutdown window also after giving this code
Process[] processlist = Process.GetProcesses("Avinash");
foreach (Process theprocess in processlist)
{
theprocess.CloseMainWindow();
}
i dont want to get that shutdown window...?
|
|
|
|
|
Hi Sandhya,
The reason you're getting that shutdown window is that the GetProcesses method gets a list of all running processes on the local computer or the machine name specified as an argument, and this list includes explorer as well. So when you call CloseMainWindow(), the close signal is being sent to all running programs including explorer as well. You should do like given below:
Process[] processlist = Process.GetProcessesByName("Notepad");
foreach (Process theprocess in processlist)
{
theprocess.CloseMainWindow();
}
All the best
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
In this case only notepad had got closed and rest others are there only..
(Explorer,MyComputer.,etc...)
|
|
|
|
|
Do you have a yahoo id. If yes, send me an Add Request at ankit_incredible_2006. The problem can be solved more quickly if we have a realtime comm. link.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
All right, try like this
void CloseApplications(void)
{
string explorerPath = Path.GetDirectoryName(System.Environment.SystemDirectory);
explorerPath = Path.Combine(explorerPath.ToLower(), "explorer.exe");
Process[] processes = Process.GetProcesses();
foreach(Process process in processes)
{
try
{
if (process.MainModule.FileName.ToLower() != explorerPath)
process.CloseMainWindow();
}
catch
{
}
}
}
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
ok..thanks 4 ur reply...
what is the process name for the window shudown?
|
|
|
|
|
It's explorer.exe
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
Hello Friends,
I am having one application in Vb6 and I wanna read one image file and want to copy it at other location.
Now when I am running my VB6 application its working fine,
But when running C# application its giving me error.
So is there any difference between VB3 and C# file handling ?
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
First decide whether you are working on VB6 or VB3. And yes there's a lot of difference between file handling in C# and VB (any version that doesn't use .Net framework).
|
|
|
|
|
Hi,
I am using VB6....
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Hi,
how to rewrite the url some .aspx to .htm or my own way
i.e
in my application url is(http:/localhost/country.aspx?countryname=india)
i want to rewrite it as(http:/localhost/india.htm)
plzzz helpp me.... thx,
icanmakeiteasy
modified on Thursday, January 29, 2009 2:44 AM
|
|
|
|
|
Get it from here Use google[^]
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
i have developed a windows application using c#,now i need to run the
application by checking the MAC id of the system..if the MAC id is matching
with which i gave in code,the application should run or else it should get
turminated with a message.
Any help?
Thanks in advance..
|
|
|
|
|
Check the MAC address in the Main method before the Application.Run()...
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
ok..
can u tel me how to check by code,am new to c#
|
|
|
|
|
Try google for the code...
I think MAC address can be obtained through ManagementClass
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
Ya i have got it...but it is saying the type or namespace name 'ManagementClass' could not be found.r u missing a using directive or assembly reference?
which directive should be added?
|
|
|
|
|
Add the reference of System.Management dll to your project.
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
Thanks for ur fast reply..Its working fine
|
|
|
|