|
I like this idea...
Let me get this right though:
DummyClose function attached to FormClosing to be created.
DummyClose will cancel the OnClosing if window opaque and make it fade first.
FadeOut timer needs to call this.Close() which will check opaque and actually close.
BTW thank you for such a quick reply!!!
|
|
|
|
|
Well, it's not a dummy close, it's an event handler which cancels the close if the form is opaque and starts a timer which fades the form and then closes it again.
Welcome
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
How bout TrojanClose? lol.
|
|
|
|
|
OMG That is sooo cool!!! Now I will attempt to make this into an abstract class library I can use as a base for forms.
This is made from a Windows Application template...try it out!!!
If you copy and paste it won't work I hope most of you know that :P
WARNING: This code is just an example. I assume most of you know what to do or you wouldn't even try.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace WindowsApplication1<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
FadeIn.Enabled = true;
}<br />
<br />
private void FadeIn_Tick(object sender, EventArgs e)<br />
{<br />
Opacity += 0.005;<br />
if (Opacity > 0.995)<br />
FadeIn.Enabled = false;<br />
}<br />
<br />
private void FadeOut_Tick(object sender, EventArgs e)<br />
{<br />
Opacity -= 0.0025;<br />
if (Opacity < 0.0025)<br />
{<br />
FadeOut.Enabled = false;<br />
this.Close();<br />
}<br />
}<br />
<br />
private void DummyClose(object sender, FormClosingEventArgs e)<br />
{<br />
if (Opacity > 0)<br />
{<br />
FadeIn.Enabled = false;
FadeOut.Enabled = true;
e.Cancel = true;<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
It sounds pretty cool, I reckon if you wrote up an article about a new base Form class which offered this, a lot of people would use it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm still pretty new to this site and I have never written an article before. Though I have read a few of them from here before and...well...some of them make me cringe sometimes the way they are laid out. Would you be willing to offer some of your obvious wisdom into helping me complete this task via e-mail? if so reply via said medium and we'll soon talk.
Thank you...
|
|
|
|
|
You need to confirm your email address before I can send you an email. I'd give you my email address publically, but who knows what email I'd get if I did that ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
hi all
I wanted a way to kill a spesific proccess for example winword.exe for a spesific user ( the user that runs the program)
there is more than one user logged on to the server so i cant have it kill all winword.exe's
any idea on how to do this?
|
|
|
|
|
You may have to P/Invoke OpenProcessToken (advapi32)[^]. Get the token information and check if the username and the process name are the one you want to kill. Get the handle and using a win32 method kill the application.
|
|
|
|
|
I was thinking more something like
For Each proc As Process In Process.GetProcessesByName("process name here") proc.CloseMainWindow() 'ask the process to exit.
proc.WaitForExit(10000) 'wait up to 10 seconds.
If Not proc.HasExited Then
proc.Kill() 'force the process to exit.
End If
Next proc
But this is in VB
|
|
|
|
|
Well, that's trivial to convert to C#.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I don't think you can get the user running the process by using the System.Diagnostics.Process class. You will have to either use P/Invoke as I suggested before or you could use WMI to get the user name of the process.
System.Management.ManagementObjectSearcher moSearch;
string sQuery = "";
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("winword");
foreach (System.Diagnostics.Process p in processes)
{
sQuery = "Select * From Win32_Process Where ProcessID = " + p.Id;
moSearch = new System.Management.ManagementObjectSearcher(sQuery);
string[] args = new string[5];
foreach (System.Management.ManagementObject mo in moSearch.Get())
{
mo.InvokeMethod("GetOwner", args);
if (args[0] == strNameToSearch)
System.Diagnostics.Process.GetProcessById(p.Id).Kill();
}
}
|
|
|
|
|
I have a small problem with System.Management
do I need to import something to make this work?
|
|
|
|
|
i found this
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName(textBox1.Text))
{
proc.CloseMainWindow();
proc.WaitForExit(10000);
if (!proc.HasExited)
{
proc.Kill();
}
}
but im having trouble inputing the proccess i want to kill
it seems like no mater what i enter it allways returns a null value to proc
|
|
|
|
|
Hello,
Have you checked the name of the process in the taskmanager?
Have you debugged the foreach, are you entering it?
You should also dispose your process instances, even if you don't kill the instance.
proc.Dispose();
Hope it helps!
All the best,
Martin
|
|
|
|
|
yes its "WINWORD.EXE"
yes i am entering it only once
im not sure what you mean by dispose():
where would i put that and why. im not trying to dispose a proccess that has been created by me
|
|
|
|
|
Hello,
OK, So you are entering the loop, that means he found an instance.
So whats the problem now?
crash893 wrote: im not sure what you mean by dispose():
where would i put that and why. im not trying to dispose a proccess that has been created by me
Disposing frees the memory from any connections, so that the GarbadgeCollector (GC) can free the memory.
With the GetProcessesByName method you created an instance (or more) of the process class (Has nothing to to with creating an new winword instance).
You would also have to (or should) dispose the instances if you don't kill the process.
In your code this would mean:
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName(textBox1.Text))
{
proc.CloseMainWindow();
proc.WaitForExit(10000);
if (!proc.HasExited)
{
proc.Kill();
}
proc.Dispose();
}
All the best,
Martin
|
|
|
|
|
everything looked like its working right but i ran into a small snag
I ran it on a terminal server ( where many people log on to run apps) and the proccess killed EVERY proccess with the name i wanted (not good)
Here is an example of what i see in taskman
Red is the scope of what it killed I am hopeing to narrow it down to who ever runs it ( in this case me rbarbrow) in BLUE
[IMG]http://i13.tinypic.com/6bcvou9.png[/IMG]
|
|
|
|
|
Hello,
Sorry for the late response!
Maybe the process member "MachineName" helps you to find the wright process.
All the best,
Martin
|
|
|
|
|
1.
int ThisSession = System.Diagnostics.Process.GetCurrentProcess().SessionId;
2.
int thisPID = System.Diagnostics.Process.GetCurrentProcess().Id;
3.
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName(application))
4.
{
5.
if (proc.SessionId == ThisSession)
6.
{
7.
proc.CloseMainWindow();
8.
proc.WaitForExit(Wait);
9.
if (!proc.HasExited)
10.
{
11.
proc.Kill();
12.
}
13.
proc.Dispose();
14.
}
|
|
|
|
|
Does this mean you are happy with the "SessionId" property?
|
|
|
|
|
it does what i need
namely doesnt kill all the winword.exe's but just he on of the user who is running my prgram
my other thing was to find out if winword.exe is respoinding
proc.responding
and
what the current cpu load is ( im still not sure how to do that)
|
|
|
|
|
Hello,
crash893 wrote: what the current cpu load is ( im still not sure how to do that)
If you whant it for overall system you could use System.Diagnostics.PerformanceCounter like this:
System.Diagnostics.PerformanceCounter cpuCounter = new System.Diagnostics.PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
string actusage =cpuCounter.NextValue()+"%";
If you need it for a special process look at this article: http://www.codeproject.com/csharp/processescpuusage.asp[^]
Hope it helps!
All the best,
Martin
|
|
|
|
|
that kinda of works
ill post code once i get it working spesificly
|
|
|
|