How to close 32 bit and 64 bit programs in C#
this code works to close 64 bit programs after i pick the program.
private void btnSleep_Click(object sender, System.EventArgs e)
{
string processName = ExtractProcessName(ofdBrowse1.FileName);
foreach(Process p in Process.GetProcesses())
{
if(0 == String.Compare(processName, p.ProcessName, true))
{
p.CloseMainWindow();
}
}
}
private string ExtractProcessName(string fileName)
{
string processName = fileName;
int index = processName.LastIndexOf("\\");
if(-1 != index)
{
processName = processName.Substring(index + 1, processName.Length - index - 1);
}
processName = processName.ToUpper();
processName = processName.Replace(".EXE", "");
return processName;
}
How can I get this code to close both 32 bit and 64 bit programs?
Re: How to close 32 bit and 64 bit programs in C#
This should work for 32bit programs too. It looks like you're navigating to the executable in your file system.
32 bit apps on a 64bit OS are normally stored in C:\Program Files (x86) instead of c:\Program Files
Does that help?
Re: How to close 32 bit and 64 bit programs in C#
Have you tried it and it doesn't work, or are you just asking? Because it should work. You can only try to add call to Proces.Close().
Re: How to close 32 bit and 64 bit programs in C#
I ran your program and closed both 64bit and 32bit Internet Explorer. I'm running 64bit Windows 7.
Re: How to close 32 bit and 64 bit programs in C#
I can close windows media player (64) but but can't close blaze media pro(86)
Re: How to close 32 bit and 64 bit programs in C#
Ok I seem to be able to close 32 bit programs that don't require me to say yes to start the program