Help with solving this code error?

I am getting this error for the code below.  The code actually connects fine, then when it gets to the "inParams..." line it give the error.

I am simply trying to use the WMI to access a remote server that runs Windows 2000, and start one of the native applications, and get a return.  My ID has full permission to the box.

*******************ERROR*******************************
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in system.management.dll
Additional information: Access is denied.
********************************************************

It connects to the server alright, but then errors out at this line.
***********LINE FOR THE ERROR*****************************
inParams = processClass.GetMethodParameters("Create");
********************************************************

Can someone help with this error and look at my code to see what I may be doing wrong?
Cheers

using System;
using System.Management;
namespace ConsoleApplication1
{

public class RemoteConnect
{
      public static void Main()
      {

            //Build an options object for the connection
            ManagementClass processClass = new ManagementClass("Win32_Process");
            processClass.Scope.Path.Server = @"myIP";

            ConnectionOptions options = new ConnectionOptions();
            options.Username = "myID";
            options.Password = "myPassword";

            //Make a connection to a remote computer using these options
            ManagementScope scope = new ManagementScope("\\\\MyIP\\root\\cimv2", options);
            scope.Connect();

            try
            {                        
                  
                  if (scope.IsConnected)
                  {
                        Console.WriteLine("We are connected.");
                              
                  }
                  }            
            catch
            {
                  Console.WriteLine("An Error Occurred:");            
            }       
            //Get an input parameters object for this method
            ManagementBaseObject inParams = null;
            
            inParams = processClass.GetMethodParameters("Create");

            //Fill in input parameter values
            inParams["CommandLine"] = "ap.exe";

            //Execute the method
            ManagementBaseObject outParams = processClass.InvokeMethod ("Create", inParams, null);                              
            //Display results
            //Note: The return code of the method is provided in the "returnValue" property of the outParams object
            Console.WriteLine("Creation of calculator process returned: " + outParams["returnValue"]);
            Console.WriteLine(outParams.ToString());
            Console.WriteLine("Process ID: " + outParams["processId"]);
      }}}
LVL 1
g118481Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chester_M_RagelCommented:
I checked your code in my machine and it worked without any errors.  "My ID has full permission to the box". Are you sure about this?
0
jk_vrCommented:
It seems that the user with supplied login credientials dont have enough permission to start a process. Please check it.
0
g118481Author Commented:
I double checked the loging ID and password, and it has full 'Admin' rights.
When I run the program my console pops up and it displays the "We are connected" message.
Which tells me that the ID and password is good.  But then when it tries to start the ap.exe program, it errors out.

Any ideas on this.  Any way I can test differently?

Cheers
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Chester_M_RagelCommented:
Can you use the default admin account(administrator) and test?
0
g118481Author Commented:
Yes, I am using the default 'Administrator' ID and password.  I can map a drive to the box. I can login with PCAnywhere with this ID and perform any task.  Also, I can login using Terminal Services Connections utility with this ID.

Is there something I have to set on the box in order for remoting (System.Management, WMI) to be able to function?
I am stuck here.  If I don't get this to work, my manager will certainly be most upset with me.

Any suggestions are most welcome.

HELP!
0
Chester_M_RagelCommented:
Sorry friend, I did a small change in your code.. Now only I figured it out. Remove

processClass.Scope.Path.Server = @"myIP";

from your code.

Hope it will work now.
Chester.
0
g118481Author Commented:
Chester,

I deleted the line "processClass.Scope.Path.Server = @"myIP";
But now instead of running the "ap.exe" program on the remote PC, the program runs on my local test machine.

How can I correct this.  I am increasing the points for this question.

Cheers
0
Chester_M_RagelCommented:
After you create the scope, put this code.

processClass.Scope = scope;
0
g118481Author Commented:
Chester,

I added "processClass.Scope = scope;", but the program stops at this line "inParams = processClass.GetMethodParameters("Create");", and gives this error message:

An unhandled exception of type 'System.Management.ManagementException' occurred in system.management.dll
Additional information: Not found
0
Chester_M_RagelCommented:
I'll post the the code which I'm using. It works fine whitout any errors...

using System;
using System.Management;
namespace ConsoleApplication1
{

      public class RemoteConnect
      {
            public static void Main()
            {

                  //Build an options object for the connection
                  ManagementClass processClass = new ManagementClass("Win32_Process");
                  
                  ConnectionOptions options = new ConnectionOptions();
                   options.Username = "myID";
                                                 options.Password = "myPassword";

                                               //Make a connection to a remote computer using these options
                                               ManagementScope scope = new ManagementScope("\\\\MyIP\\root\\cimv2", options);
                  scope.Connect();

                  try
                  {                    
               
                        if (scope.IsConnected)
                        {
                              Console.WriteLine("We are connected.");
                         
                        }
                  }          
                  catch
                  {
                        Console.WriteLine("An Error Occurred:");          
                  }      
                  //Get an input parameters object for this method
                  ManagementBaseObject inParams = null;
                  processClass.Scope = scope;
                  inParams = processClass.GetMethodParameters("Create");
                  

                  //Fill in input parameter values
                  inParams["CommandLine"] = "calc.exe";

                  //Execute the method
                  ManagementBaseObject outParams = processClass.InvokeMethod ("Create", inParams, null);                        
                  //Display results
                  //Note: The return code of the method is provided in the "returnValue" property of the outParams object
                  Console.WriteLine("Creation of calculator process returned: " + outParams["returnValue"]);
                  Console.WriteLine(outParams.ToString());
                  Console.WriteLine("Process ID: " + outParams["processId"]);
                  Console.ReadLine();

            }
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
g118481Author Commented:
Chester,

Your suggestion runs.  Thanks for the valuable information.  I will be opening two or three more high value questions this week, if you are interested.  

Thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.