[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using System.Management.ManagementPath

Posted on 2007-10-11
8
Medium Priority
?
1,649 Views
Last Modified: 2010-05-18
Hi,

im using System.Management for access to some machine and run a command.
the connection work and also the execute command but my problem is when
i try to run a command file from another location that not recognize in the path variable enviroment
it's cannot been done.
my problems is how to make the command to open from my input location like for example:
D:\Projects\IAI Migration\Deployment\DocSiteExport.

my relative code is:
...
...
...
path = new System.Management.ManagementPath("\\\\" + MachineName + "\\root\\cimv2:Win32_Process");
scope = new System.Management.ManagementScope(path, options);
scope.Connect();
opt = new System.Management.ObjectGetOptions();
classInstance = new System.Management.ManagementClass(scope, path, opt);
inParams = classInstance.GetMethodParameters("Create");
inParams["CommandLine"] = Command;

...
...
...

thanks for the help :)
0
Comment
Question by:bwz
  • 4
  • 4
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20057960
Leave off the ':Win32_Process' portion of the path, and select that when creating the ManagementClass instead.

Bob
0
 

Author Comment

by:bwz
ID: 20058055
hi,
you mean that i config the path location after this line:
classInstance = new System.Management.ManagementClass(scope, path, opt);      ?

i'm not sure that i got your poiint.

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20058235
Oops, I did it again :((

What is the problem that you are having opening the process on the remote machine?

I came up with this example class to try a slightly different approach:

using System;
using System.Management;

public class Win32_Process
{

    public static void RunCommand(string commandLine, string machineName, string userName, string password)
    {

        ManagementPath path = new ManagementPath(@"\\" + machineName + @"\root\cimv2:Win32_Process");

        ConnectionOptions options = new ConnectionOptions();
        options.Username = userName;
        options.Password = password;
        options.Impersonation = ImpersonationLevel.Impersonate;
        options.Authentication = AuthenticationLevel.PacketPrivacy;

        ManagementScope scope = new ManagementScope(path, options);

        ManagementClass classInstance = new ManagementClass(scope, path, new ObjectGetOptions());

        classInstance.InvokeMethod("Create", new object[] { commandLine });
    }
}

Bob
0
Industry Leaders: 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:bwz
ID: 20058395
ok, thanks
i will check it on sunday, bu tell me please only one more things
what shoult i insert to path string?
can i pass this line for example ?" D:\Projects\IAI Migration\Deployment\DocSiteExport "

thanks again.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20058570
Is 'DocSiteExport' the executable?

Bob
0
 

Author Comment

by:bwz
ID: 20063442
no its the part of the path.
i'm finally run a command file the exists in that path
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 150 total points
ID: 20065353
I would think that you need to specify the full path for the executable:

D:\Projects\IAI Migration\Deployment\DocSiteExport\FileNameToExecute.exe

Bob
0
 

Author Comment

by:bwz
ID: 20066208
yea,
i'm actually did it and it's work (run with the full path) but i thought that there is another way.
becaue i'm got a different behaviour when i run it from the machine and run it from the c# program.
(but it's another issue i gess).
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses

834 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