473,507 Members | 6,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

process.GetProcessesByName getting error


I have a service that 1) uses filewatcher to watch a directory on a
remote machine.
2) checks if a certain application is running on the local machine
before starting it.

The problem is while checking for an existing instance of the
application. I do the following code :
Process[] processes = Process.GetProcessesByName(stProcName, localcpu);
Where stProcName is the process I am checking
localcpu is the local machine name.

When it trys to execute this command it gives me an error stating that
it cannot get the process information from the remote machine. I'm not
sure why it is trying to look at the remote machine or how what is
telling it to look over there. The only thing that should be looking
over to the remote machine is FileSystemWatcher.
Thanks for any help
Carol

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
5 5413
Why using the overload that takes a machine name? You know, that localcpu is
the local machine, but for the code any name for machineName is considered
remote.
Try using GetProcessesByName(stProcName); and you will get the same
exception, simply because the service has no sufficient rights to enumerate
all process.

Willy.

"hangten" <no******@pacbell.net> wrote in message
news:Oa***************@TK2MSFTNGP11.phx.gbl...

I have a service that 1) uses filewatcher to watch a directory on a
remote machine.
2) checks if a certain application is running on the local machine
before starting it.

The problem is while checking for an existing instance of the
application. I do the following code :
Process[] processes = Process.GetProcessesByName(stProcName, localcpu);
Where stProcName is the process I am checking
localcpu is the local machine name.

When it trys to execute this command it gives me an error stating that
it cannot get the process information from the remote machine. I'm not
sure why it is trying to look at the remote machine or how what is
telling it to look over there. The only thing that should be looking
over to the remote machine is FileSystemWatcher.
Thanks for any help
Carol

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
What rights does it need ? I gave it admin. to see if it would work and
it did. But I can't do that on this system. Is there another way to
handle this ? Maybe another way to check if the application is running
?
Thanks
Carol
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

"hangten" <no******@pacbell.net> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
What rights does it need ? I gave it admin. to see if it would work and
it did. But I can't do that on this system. Is there another way to
handle this ? Maybe another way to check if the application is running
?


Yes, use the System.Management classes, next sample should get you started..

using System;
using System.Management;
class Sample_SelectQuery
{
public static void Main() {
string processName = "explorer.exe";
Console.WriteLine(IsProcessRunning(processName).To String());
}
private static bool IsProcessRunning(string procName)
{
bool ret = false;
SelectQuery selectQuery = new SelectQuery("select Name from Win32_Process
where name='" + procName + "'");
using(ManagementObjectSearcher searcher = new
ManagementObjectSearcher(selectQuery))
{
ManagementObjectCollection moc = searcher.Get();
if (moc.Count != 0)
{
ret = true; // OK process is running
}
return ret;
}
}
}

Willy.
Nov 16 '05 #4

Willy - Thanks for the info.. I added this code but am getting an error
when it does the moc.Count line of code. Here is what I added :
SelectQuery selectQuery = new SelectQuery("select Name from
Win32_Process where name='" + stProcName + "'");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(selectQuery);

ManagementObjectCollection moc = searcher.Get();
if (moc.Count != 0)
return true; // OK process is running
else
return false;

The error I am getting is the following :
COM object that has been separated from its underlying RCW can not be
used.

Am I missing something ?

The error was thrown at
System.Management.ManagementObjectCollection.GetEn umerator()
at System.Management.ManagementObjectCollection.get_C ount() at
ProcessExist.ProcExist.InstanceExist()

Thanks for your help
Carol
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Willy - Disregard my last message. I was getting that error because I
was in debug mode. Don't know why but it was OK afterwards. Also, I
didn't have the .exe in my variable that I was checking. It works great
and I want to thank you very much...

Carol

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3524
by: rollasoc | last post by:
Hi, One of our customers seem to be having an issue with our software getting the following exception on running the app. 'System.InvalidOperationException', with the message "Process...
1
8469
by: Max | last post by:
I'm trying to get the process id of some application and I get an error for this line: Process myApplications= Process.GetProcessesByName("MyApplication"); The error says: ...
9
21586
by: DraguVaso | last post by:
Hi, I want my application to bring another application to the Front. I thought best way to do this was by the Process-model: Dim c As Process = Process.GetCurrentProcess() Dim p As Process...
3
1260
by: Nikolay Petrov | last post by:
I have a class which starts a process and redirects it's output and input. My class have a method which starts the process and another which stops it. How can I check if the process have been...
5
1752
by: kd | last post by:
Hi All, If the name of a process is known, is it possible to check whether it is in execution? What I did was to fetch all the processes running on the system using Process.GetProcesses() and...
2
19076
by: kd | last post by:
Hi All, Process.GetProcessesByName() is not giving the expected results. Here is a sample code. Dim TestProcess() As Process Try TestProcess= Process.GetProcessesByName("Test.exe") If...
4
1606
by: Miro | last post by:
I'm using VB.Net 2003 I have code - it works great - to kill a process(s) if they are running. ---- Dim myProcesses() As Process 'Funny - withouth the () in the myProcesses it does not work...
4
2865
by: =?Utf-8?B?VkIgSm9ubmll?= | last post by:
I am at my witless end here, please help! I have an ASP.Net aspx web page, hosted on Windows Server 2003, that receives a query string with the path to an autocad drawing file selected from a...
2
2599
by: djidan | last post by:
hello, can anyone tell what the hell is the problem with my program...? i built a program that getting all the process from windows by the name of "excel", when i compile it and creating a .exe...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.