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
Solved

How to use GetProcess() for remote sytems

Posted on 2008-06-25
8
2,178 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

837 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