InvalidOperationException error on GetProcessesByName

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I am using dotNet 2003 to develop my application

I prevent my app should run only one instance per time by using GetProcessesByName() function to check instance. But I found problem with Win2K Chinese Version when running the app that has checked instance before normally run the app. The error throw an InvalidOperationException to my app

I have try with my computer (WinXP) but no problem occur

How should I do with this situation or you have any solution for me to check the instance to avoid to use GetProcessesByName() function

Thanks
KP
 
Hi,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to run just one instance
of a process in the memory.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I have tested the code below, I can not reproduce the problem.
try
{
Process [] localByName = Process.GetProcessesByName("calc");
Console.WriteLine(localByName.Length);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}

I think you may try to use the Mutex to implement the Singleton one
instance of a process.
You may declare an static mutex variable and attempt to get the mutex every
time the application is going to run, if mutex can not be gotten then there
should be one instance running.

Here is an code sample link.

Windows Forms Singleton Application Frameworks By default, every time a
Windows Forms application starts, .NET launches a new process. This utility
contains an alternative Application object which enables a singleton
application - if an instance is already running, it ignores the request to
create a new instance.

http://www.idesign.net/idesign/DesktopDefault.aspx?tabindex=5&tabid=8


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter

Did you try with WinXP Chinese version

I have try with WinXP English version before but no problem found

Cheers
KPH
 
Hi,

Thanks for your quickly reply!

I have tried the code on a windows 2000 chinese version with vs.net 2003
chinese enterprise version. Here is the behavior I got by running the code.
try
{
Process [] localByName = Process.GetProcessesByName("calc");
Console.WriteLine(localByName.Length);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}

If there is no calc in the memory the localByName.Length will be 0, if
there is one calc in the memory, the localByName.Length will be 1. The
catch block will not be called. If you have tried my code on windows 2000
chinese version, what the exact error message you get from the catch block
below.
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}


As for windows xp chinese version, can you specify more detailed about your
version so that we can build a test environment.
e.g. have you installed the windows xp service pack 1?
the vs.net 2003 you are using is of chinese version or english version?

BTW: Did the link about singleton process instance using mutex work for
you? If you still have any concern on this issue, please post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter

I have already try singleton process, it look good and I can use it with my program

OS requirement of my program are
1. Win2K SP3 or late
2. WinXP SP1 or late
3. WinN

Framework: dotNet Framwork 1.
VS: dotNET 200

Now that I really would like to know, what is the cause of problem of InvalidOperationException when calling GetProcessesByName function.
Because this exception is only one exception can occured for this function

Thanks
KPH
 
I have also tested on a IBM Thinkpad a22p with Win2K pro. service pack 4
The small test program also throws exception.

I think the service pack or latest update has nothing to do because before I update the machine we got this exception from our application containning GetProcessbyName.

In short, I can assure you that it is only happen on some machines. I would like to know how could I help you pinpoint the problem e.g. what information do I need to gather from such machine in order to analyze

Best regards
KPH
 
Hi,

Thanks for your quickly reply!

I want to confirm with you that "The small test program" you refer to is
the same code in my previous posts?

I mean the name you pass into the GetProcessesByName is an english name or
another one?

Process [] localByName = Process.GetProcessesByName("calc");

If no, can you send me you test program project by removing "online" from
my email address, I will appreciate your efforts.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter

It is exactly the example that you post. I just made an console application for that.

Best regards
Warut
 
Hi Warut,

Thanks for posting in the community.

For further troubleshooting,
I think you may also try to check if the performance counter registry entry
has been corrupted. To resolve this symptom, you could Export 009 registry
key (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Perflib\009) from a good system that has the identical
Operating System/Service Pack Level and Import it into the bad system.

If the above does not work, the following knowledge base article documents
how to build performance counter/help information from scratch, if the
system is badly
affected.
300956 How to Manually Rebuild Performance Counter Library Values
<http://support.microsoft.com/?id=300956>

Also you may try to enable the performance counter.
For additional information on disabling/enabling performance counter,
please refer
to the following KB article:

248993 PRB: Performance Object Is Not Displayed in Performance Monitor
<http://support.microsoft.com/?id=248993>

Does this problem occur after the above steps? Please let me know your
testing result.
If no, can you provide the exact detailed error messge you get from the try
catch block.
You may get it by writeline the ex as below.
Console.WriteLine(ex.ToString())

Please post the exact error message you got from the line above.

To isolate the problem add the administrator account into the "Performance
Monitor Users" Group and try to run the test program as administrator
account to if the problem persists.

I look forward to your reply. Thank you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Warut,

Have you tried my suggestion that trying to check if the performance
monitor works on your machine, if you still have any question on this
issue, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter

I am trying;however, I don't have access to that particular machine anymore.
I had only system state data backup from the trouble machine.
I restored the system state to alternate location and trying to load files in the regback folder into the hive by using regedit

Unfortunately, it is not quite clear from the registry that is there any problem with their perfLib
What do you suggest for me to do next

Best regards
Warut
 
Hi Peter

If restoring system state data into alternate location and the file SOFTWARE is the whole hive of registry in HKLM then I have found that the restored registry key PerfLib doesn't has key 009 in its compared to other healthy Windows 2000 machine

Is this can be an indicator of a problem on Perflib on that particular machine

Best regards
Warut
 
Hi Warut,

Thanks for your quickly reply!

From your descript, counter and Help registry values are missing in the
registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009

To resolve this problem, either you could Export 009 registry key from a
good
system that has the identical Operating System/Service Pack Level and
Import it
into the bad system or manually rebuild all the counters following the
instruction
given in Q300956

300956 How to Manually Rebuild Performance Counter Library Values
<http://support.microsoft.com/?id=300956>

After that, you can run the perfmon from the run dialog to make sure if the
performance monitor has worked by following the steps below.

1. Run perfmon
2. Click the "+" (Add) in the toolbar of performance monitor and check if
the Processor is in the Performance object.
3. If no, it may be disabled, you may need to re-enable it by following the
KB article below.
248993 PRB: Performance Object Is Not Displayed in Performance Monitor
<http://support.microsoft.com/?id=248993>

You may have a try and let me know the result.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter

Well, I tried backup system state data from a good machine and restored to alternate location.
The result shows that there is also no HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009 when loading hive of restored registry. Thus this fact is not enough to conclude that the registry of suspect machine is corrupted.

Is there any other way to further analyze from system state data?

Best regards
Waru
 
Hi Warut,

Thanks for your quickly reply!

To isolate the problem, we need to firstly make sure if the performance
monitor will work on suspect machine.

To make the test, I suggest you open the preformance monitor and add an
counter to one process which is running to see if this will work.

When you select the process from the performance object, you will see the
current running instance process, you may try to add a counter to it to see
if this will work.

In this way, we will isolate the problem.

I will appreicate your efforts.

If the performance monitor works fine on the suspect machine. Please post
the complete stack trace for the InvalidOperationException you get when you
call the GetProcessesByName here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Peter

Unfortunately, I can't access the suspect machine anymore
Is there any way to restore system state data excluding boot files

System state data contains boot files, COM+ registration... and registry and it seems to me that the boot files create a problem when restoring into other machine rather than original one.

Best regards
Warut
 
Hi Warut,

From your description I understand that you can directly access the suspect
machine, then I am confused about how you restrore the system state data
into the machine?

Also what do you mean by system state data, in the KB article I provide for
you in my last post,
300956 How to Manually Rebuild Performance Counter Library Values
<http://support.microsoft.com/?id=300956>

We do not need to restore all the system state data.

And after we confirm that the registry information for performance monitor
is fine, we also need to confirm that the performance monitor is enabled,
as I refer to another KB article in my last post.

Can you turn to other person who is able to access the suspect machine to
do it for you?

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top