Solved

How to use GetProcess() for remote sytems

Posted on 2008-06-25
8
2,076 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Aspnet xml 2 36
Pass through dll 2 38
Image(7) 1 37
C# replace string in void with dR["myData"].ToString() 3 10
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

23 Experts available now in Live!

Get 1:1 Help Now