Solved

How to use GetProcess() for remote sytems

Posted on 2008-06-25
8
2,144 Views
Last Modified: 2008-06-26
Greetings:

I have  a routine that determines whether a process is alive   Looks like this:

public bool IsProcessAlive(string hostname, string processName)
{
 Process p = GetProcess(hostname, processName);

 if (p == null)
 {
  return false;
 }
 else
 return !p.HasExited;
}

If I pass a system name which is not the local machine I get the error:

Feature is not supported for remote machines.  (NotSupportedException was unhandled)

What would be the work around for this?  Is there another function I should be using instead?

Thanks
0
Comment
Question by:John500
  • 4
  • 3
8 Comments
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 21866954
Can you provide the source for your GetProcess method?
0
 
LVL 7

Expert Comment

by:nsanga
ID: 21867306
you might not have required permissions on the target machine to view the processes..........

also you can use..

dim p() As Process=System.Diagnostics.Process.GetProcessesByName(processname, hostname)
0
 

Author Comment

by:John500
ID: 21868246
rob:

 public Process GetProcess(string hostname, string processName)
        {
            Process[] ps = Process.GetProcessesByName(processName, hostname);

            if (ps.Length == 0)
                return null;
            else
                return ps[0];
        }

nsanga,

Are you saying that 'GetProcessesByName()' has no restrictions regarding remote machines?  Since this is C# I'm guessing the statement should read:

Process=System.Diagnostics.Process.GetProcessesByName(processname, hostname)  // without the 'Dim p()'

What does 'p()' represent?


0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:John500
ID: 21868349
Now I understand - I'm already using 'GetProcessesByName()' :

Process[] ps = Process.GetProcessesByName(processName, hostname);

Hence, the problem is actually with the following line:

 return !p.HasExited;

This line is the one not supported for remote machines.  Any ideas how I can change this try/catch?

Thanks
0
 
LVL 7

Expert Comment

by:nsanga
ID: 21872758
0
 

Author Comment

by:John500
ID: 21874023
Appreciate the link.  I just wish the person who posted that issue would have included a more detailed answer.  They end it like this:

>> using ConnectionOptions for authentication solved the problem.

I'm wondering just what this means.  The function used here only has two options:

GetProcessesByName(string ProcessName, string MachineName)
GetProcessesByName(string ProcessName)

What authentication options am I missing?
0
 
LVL 7

Accepted Solution

by:
nsanga earned 500 total points
ID: 21874673
you have to use the second method to get the processes......

and regarding authentication......you have to use

System.Management.ConnectionOptions class.......( add reference to System.Management.dll )


please look at this link........this will give you an idea.....on how to use ConnectionOptions.authentication

http://msdn.microsoft.com/en-us/library/system.management.connectionoptions.authentication.aspx




0
 

Author Comment

by:John500
ID: 21876486
Thanks for the reference.  My thoughts are:  If 'GetProcessesByName() is able to connect remotely but not able to use 'p.HasExited'  I'll just use another exit condition.  The small time elapsed from the successful connection to the call to 'p.HasExited' isn't worth worrying about.

I used the following:

public void IsProcessAlive(string hostname, string processName)
        {
            try
            {
                System.Diagnostics.Process p = GetProcess(hostname, processName);

                isProcessAlive_ = false;

                if (p != null)
                {
                    isProcessAlive_ = true;
                }
            }
            catch (Exception e)
            {
                if (e.Message.Equals("Couldn't connect to remote machine."))
                {
                    isServerAlive_ = false;
                }
            }
        }
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Export import database 4 51
Turn on intranet settings 1 55
Angular - break the dataset in chunks? 7 50
Facial recognition to look through the whole database for a person 3 61
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question