Solved

How to use GetProcess() for remote sytems

Posted on 2008-06-25
8
2,204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTML - Color not displaying correctly in EMAIL. 6 56
insert value of checklistbox checked 4 39
Please explain purpose of GZIP 4 61
Visual C# Windows Project - Clone Form 4 26
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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