| Hi Willy,
| a couple of questions:
| 1. this line:
| ManagementScope scope = new ManagementScope(@"\\" + remMachine +
| @"\root\cimv2", co);
| seems to reference a folder on the root called 'cimv2'. I don't have a
| folder like that. Do I need one?
|
No it does not refer to a folder , it refers to a WMI namespace.
The forder or file you are refereing to is specified in the object path:
string fileName = "C:\\somedir"; // this is the input file
string objPath = "Cim_LogicalFile.Name='" + fileName + "'"; // HER file name
is the input path
| 2. this line:
| ManagementBaseObject inputArgs = remFilePath.GetMethodParameters("Copy");
| always gives me an 'access denied' error. Any thoughts?
|
You need to "remote enable" the WMI namespace on the server, run wmimgmt.msc
and change the security settings on root\cimv2 make sure that the user
account used to connect has remote enable permissions.
| Thanks,
| Michael
|
|
| "Willy Denoyette [MVP]" wrote:
|
| > No it copies whatever you specify as the input/output filename.
| > This will copy the somedir to a new folder copydir
| > string fileName = "c:\\somedir";
| > ....
| > inputArgs["FileName"] = "c:\\copydir";
| >
| > Please consult the documentation (System.Management and WMI) in MSDN,
don't
| > use program samples blindly without knowing what it's actually doing.
| >
| > Willy.
| >
| >
| >
| > | > | Willy, this code seems to want to copy a file on that server. I am
trying
| > to
| > | copy an entire folder on the server.
| > |
| > | Thanks,
| > | Michael.
| > |
| > |
| > | "Willy Denoyette [MVP]" wrote:
| > |
| > | > You need to add a reference to the System.Management.dll in your
project
| > | > settings.
| > | >
| > | > Willy.
| > | >
| > | >
| > | > | > | > | Willy,
| > | > | thanks for the help. But when I start to type in the code you
gave
| > me
| > | > and
| > | > | I get to the line: System.Management; The intellasence does not
have
| > the
| > | > | word 'Management' in there. How do I access it? I am running
VS2005.
| > | > |
| > | > | Thanks,
| > | > | Michael.
| > | > |
| > | > | "Willy Denoyette [MVP]" wrote:
| > | > |
| > | > | > Here's a complete sample illustrating the use of
System.management
| > to
| > | > copy
| > | > | > files on a remote server.
| > | > | > This has the advantage that the file is copied locally (o the
| > server)
| > | > | > without being passed back and forth to/from the workstation
where
| > this
| > | > | > program runs.
| > | > | >
| > | > | > using System;
| > | > | > using System.Management;
| > | > | > public class Program{
| > | > | >
| > | > | > public static void Main() {
| > | > | > string remMachine = "remoteservername"; // this is the name of
the
| > | > file
| > | > | > server
| > | > | > string fileName = "C:\\somedir\somefile"; // this is the input
| > file
| > | > | > string objPath = "Cim_LogicalFile.Name='" + fileName + "'"; //
| > watch
| > | > the
| > | > | > single quotes!!
| > | > | > ConnectionOptions co = new ConnectionOptions();
| > | > | > // server account credentialswith appropriate privileges to
in/out
| > file
| > | > | > paths
| > | > | > co.Username = "user";
| > | > | > co.Password = "pwd";
| > | > | > ManagementScope scope = new ManagementScope(@"\\" + remMachine
+
| > | > | > @"\root\cimv2", co);
| > | > | > using (ManagementObject remFilePath = new
| > ManagementObject(objPath))
| > | > | > {
| > | > | > remFilePath.Scope = scope;
| > | > | > ManagementBaseObject inputArgs =
| > | > | > remFilePath.GetMethodParameters("Copy");
| > | > | > inputArgs["FileName"] = "C:\\somedir\\somecopy"; //this is
the
| > | > output
| > | > | > file
| > | > | > ManagementBaseObject outParams =
| > remFilePath.InvokeMethod("Copy",
| > | > | > inputArgs, null);
| > | > | > uint ret =
(uint)(outParams.Properties["ReturnValue"].Value);
| > | > | > if(ret == 0)
| > | > | > Console.WriteLine("Success");
| > | > | > else Console.WriteLine("Failed with error code: {0}", ret);
| > | > | > }
| > | > | > }
| > | > | > }
| > | > | >
| > | > | >
| > | > | > Willy.
| > | > | >
| > | > | >
| > | > | >
| > | > | >
| > | > | >
| > | >
| > | >
| > | >
| >
| >
| >