tags:

views:

27

answers:

1

Regarding my previous problem that is now fixed, I got another problem with the //code here part :/

foreach (ManagementObject obj in ObjSearcher.Get())
{  
    ManagementBaseObject inputArgs = obj.GetMethodParameters("CopyEx");
    inputArgs["FileName"] = "\\c:\\1stuff";
    inputArgs["Recursive"] = true;
    ManagementBaseObject outParams = obj.InvokeMethod("CopyEx", inputArgs, null);
    uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
}

I keep getting a returnvalue of 9, which is "Invalid Name". I have no idea what got an invalid name nor how to fix it. Both folder exist.

A: 

You have a leading backslash in your file name. Try removing it. I'm not aware of any file paths that have the format you're using.

Jacob
Removing the leading \ gives an error 10, which is "Invalid Level"
Wildhorn
I think you have to specify the path like this: `\\MACHINENAME\root\cimv2:Win32_Directory.Name="<your path>"`
Jacob
(and use `\\.\` for the local machine)
Jacob
No doesn't work. It gives me error 9 again.
Wildhorn
What's the entire resulting string that you're using? Inside of the `Name=""`, you have to make sure you escape (which might mean double-escaping) your string.
Jacob
inputArgs["FileName"] = @"\\"+machineName+@"\root\cimv2:Win32_Directory.Name='c:\\1stuff'";
Wildhorn
Also tried inputArgs["FileName"] = @"\\"+machineName+@"\root\cimv2:Win32_Directory.Name='c:\1stuff'";
Wildhorn
According to http://msdn.microsoft.com/en-us/library/aa389324(VS.85).aspx, error 10 means "The object specified already exists." Perhaps just @"c:\1stuff" works fine but there's already a file/directory there blocking the copy.
Jacob
Damn, it is that! Changed name and it created a new one. Now, I gotta find the command to override an already existing folder... Or that I will have to do a Delete before a Copy
Wildhorn