Solved

How to use GetProcess() for remote sytems

Posted on 2008-06-25
8
2,110 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…

948 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now