|
I need to be able to filter a proc list to only the currently logged in user. I tried using System.Diagnostics.Process.GetProccess(string name); it returns a list of process with that name for the entire computer.
How do I filter this list down? (This is for windows xp fast user switching support)
|
|
|
|
|
You can do it with WMI very easily:
http://www.codeproject.com/useritems/WMI.asp[^]
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hello all,
I'm trying to write an ownerdrawn statusbarpanel that shows the progress of a webpage d/l. like the IE one, but I having a problem. Basically the OnDrawItem event isn't being called when I need it to be called. In the ProgressChange event for the WebBrowser I'm assigning my ProgressPanel (derived from StatusBarPanel) the value it needs, but then it's never updating because the OnDrawItem event isn't being called. Now if I resize the form the panel gets drawn, unfortunately since the download is already done, the panel is full. I'm not sure how I get the OnDrawItem event to fire everytime there is a progress change. Anyone know how I could do this?
Thanks
- monrobot13
|
|
|
|
|
You need to invalidate the control to force it to redraw. try doing : this.Refresh(); in the event handler code for OnProgressChanged().
|
|
|
|
|
When I started learning about C#, I noticed the sample programs would use the funky argument-substitution notation inside Console.WriteLine , similar to printf in C:
int a = 17;
string b = "something";
Console.WriteLine("a = {0} and b = {1}", a, b);
When I finally got around to writing some code, I decided to stick with the Java approach of simply contatenating everything, which to me seems easier to read and less error prone:
Console.WriteLine("a = " + a + " and b = " + b);
I'd like to get some opinions on the pros and cons of each approach.
Why does Microsoft seem to promote the first technique? The thing is, you look at other WriteLine s, such as Debug.WriteLine and Trace.WriteLine and they don't take a variable number of arguments, so you can't use the argument-substitution technique there.
Thanks,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
I usually use the second one
Now a days... computers are so fast it doesn't matter how you do it, as long as it works. That's why I use the easier way.
But sometimes it helps to know how to use the first one, because in the first method it is easier to read the code, and modify it later.
|
|
|
|
|
Alvaro Mendez wrote:
I'd like to get some opinions on the pros and cons of each approach.
By using the argument substitution you can add additional formatting to the WriteLine call (such as pad numbers or strings) which you may or may not be able to do the other way, depending on how the ToString method is written for each variable's type.
Another advantage is if you are localizing your application you only have one string to replace instead of 2 for your example.
As you point out the con is that you aren't placing the variable right there so you need to reference back and forth to get the whole picture.
Alvaro Mendez wrote:
as Debug.WriteLine and Trace.WriteLine
A shame too, I find myself having to do: string.Format inside of the WriteLine method
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I prefer the first method since it makes the code far more readable. I'm not too sure as to whether one is more efficient than the other, it'd be interesting to see though.
I tend to use String.Format("{0}: {1}") etc. when using it with a method that doesn't directly support it.
--
Paul
"Put the key of despair into the lock of apathy. Turn the knob of mediocrity slowly and open the gates of despondency - welcome to a day in the average office."
- David Brent, from "The Office"
MS Messenger: paul@oobaloo.co.uk
|
|
|
|
|
The first way (using String.Format essentially) is a little more useful i think under a scenario like the following
Console.WriteLine("a = {0} and a = {0} and b = {1}", a, b);
vs
Console.WriteLine("a = " + a + " and a = " + a + " and b = " + b);
|
|
|
|
|
Thought I'll add me bit as well. I like former approach more, because you can do this:
Console.Write("Matches for '{1,1}': {0,-10}\t{2,10:f3}ms\t", count, b, Avg(contains));
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
How can I add or subtract value from DateTime,like this:
mydatetime = DateTime.Now – SixHour
Or
Mydatetime = DateTime.Now - SixHour and Half Minutes
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
See the AddHours method[^] or the Subtraction operator[^]. Both will do nicely.
And don't forget to visit the TimeSpan [^]object.
Try:
DateTime nm6 = DateTime.Now - new TimeSpan (6, 0, 0);
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
Thanks.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I save files from my application with an extention. I have two problem now:
1.I want when user double click on that file my application open and show the proper datas from that file.
2.When user save files ,it saves with my application icon,now its save with unknown window icon.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Mazdak wrote:
2.When user save files ,it saves with my application icon,now its save with unknown window icon.
There is quite a bit involved to do this using .net.
Take a look at this usenet post on microsoft.public.dotnet.languages.csharp. It should get you rolling.
Hey don't worry, I can handle it. I took something. I can see things no one else can see. Why are you dressed like that?
- Jack Burton
|
|
|
|
|
Thanks.
Well I found first one.I get it from command line.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I am writing a utility to check the health of an application and I would like to check if a particular Windows service is installed and if it is whether it is running or not.
I have used the System.ServiceProcess.ServiceController class to see if a service is running or not (and this works fine) but I can't find a way to trap if the service is actually installed.
I could interate through the ServiceController[] using GetServices but this seems to be a bit "clunky" particularly becauseI want to check the existence of a number of services as the utility loads.
Is there a class/method that will do this for me?
Anyone got any ideas on how to do it?
Thanks for your help
Andy
|
|
|
|
|
I don't know if I understand your problem.When you can get list of services,check the name of them if your proper names are there so they are installed,whats the problem with that?
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hi Mazy,
Thanks for the reply.
It just seems to be a lot of work when I would have expected an exception to be returned by ServiceController to say that the service is not installed.
If you use VBA and the windows API "advapi32.dll" the QueryServiceStatus method returns an error that shows if the service is installed - surely C# has an equivalent - maybe not.
Andy
|
|
|
|
|
Well,When I want to do that I just look up in ServiceController[] which used GetServices().I look just check each ServiceName property for ServiceController[] and if its there so it is installed.Its not that muck hard or caused any expetion.And I can get the status of each service by Status prperty.
Anyway,You can use QueryServiceStatus in C# too.You can use it like the way you use other win32 functions in C# but thats very hard and boring.You can write a DLL with MC++(I GUESS you can do that with VB.NET too) and do this jon in it and then it is REALLY easy to reuse it in C#.If you want to do it in this way I can help you more.
I don't think you have any other choices,there is nothing like that in .Net framework as much as I know.
HTH
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Mazy,
Many thanks for your advice.
You have confirmed my thoughts, it just seems odd that when someone has written a class that gets a service status that one of the status conditions would not be "its not installed".
I am going to opt for using ServiceConroller[].
Regards
Andy
|
|
|
|
|
I completely agree with you. Worse there doesn't seem to be any native .NET way of getting all the information you could normally get using QueryServiceStatus() that is returned in the SERVICE_STATUS structure. .NET needs to replace the ServiceStatus enum with a class.
|
|
|
|
|
This works for me..
public bool IsInstalled()
{
try
{
string str;
ServiceController sc = new ServiceController(myServiceName);
// accessing some property will throw an exception if not installed.
str = sc.ServiceName;
}
catch (Exception)
{
return false;
}
return true;
}
|
|
|
|
|
I've written a tray based application and overridden the OnClosing where I iconify the application instead of closing it. However, when I'm trying to shut down or restart my computer the program wont shut down and the computer wont reboot or shutdown until I exit the program. I know that WIndows sends the message WM_ENDSESSION when the system goes down, but how do I handle this from my hidden application in the traybar? Or is there another simple solution of this problem 
|
|
|
|
|
Is that the only method (OnClosing) you wrote an override for?
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|