Win32_Directory CopyEx Method not working.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<span style="font-size:small <span style="font-size:small
Im trying to use WMI to copy a files from my local machine to a remote machine.
The problem is I can not use SMB and it is stopped and I can not start it either.
So the only option Im left with is WMI.
After referring to posts online I wrote below code but his isnt working.


<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small static<span style="font-size:small <span style="font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small uint<span style="font-size:small <span style="font-size:small DirectoryCopy(<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small string<span style="font-size:small <span style="font-size:small node,
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small string<span style="font-size:small <span style="font-size:small SourcePath,
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small string<span style="font-size:small <span style="font-size:small DestinationPath,
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small bool<span style="font-size:small <span style="font-size:small Recursive)
<span style="font-size:small <span style="font-size:small
{





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small try
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <br/>
<span style="font-size:small <span style="font-size:small
{






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ConnectionOptions<span style="font-size:small <span style="font-size:small connOptions =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ConnectionOptions<span style="font-size:small <span style="font-size:small ();
<span style="font-size:small <span style="font-size:small
connOptions.Username =





<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "user"<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small
connOptions.Password =





<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "password"<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small
connOptions.Impersonation =





<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ImpersonationLevel<span style="font-size:small <span style="font-size:small .Impersonate;
<span style="font-size:small <span style="font-size:small
connOptions.EnablePrivileges =





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small true<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small






<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small string<span style="font-size:small <span style="font-size:small objPath =
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small @"\"<span style="font-size:small <span style="font-size:small + node +
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small @"rootcimv2:Win32_Directory.Name="<span style="font-size:small <span style="font-size:small +
<span style="font-size:small <span style="font-size:small






<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small """<span style="font-size:small <span style="font-size:small + SourcePath.Replace(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "\"<span style="font-size:small <span style="font-size:small ,
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "\\"<span style="font-size:small <span style="font-size:small ) +
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small """<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Console<span style="font-size:small <span style="font-size:small .WriteLine(objPath);
<span style="font-size:small <span style="font-size:small






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementScope<span style="font-size:small <span style="font-size:small manScope =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementScope<span style="font-size:small <span style="font-size:small (objPath,
connOptions);
<span style="font-size:small <span style="font-size:small
manScope.Connect();






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ObjectGetOptions<span style="font-size:small <span style="font-size:small objectGetOptions =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ObjectGetOptions<span style="font-size:small <span style="font-size:small ();
<span style="font-size:small <span style="font-size:small






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementPath<span style="font-size:small <span style="font-size:small managementPath =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementPath<span style="font-size:small <span style="font-size:small (<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Win32_Directory"<span style="font-size:small <span style="font-size:small );
<span style="font-size:small <span style="font-size:small






<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small using<span style="font-size:small <span style="font-size:small (<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementClass<span style="font-size:small <span style="font-size:small dir
= <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small new<span style="font-size:small <span style="font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementClass<span style="font-size:small <span style="font-size:small (manScope,
managementPath, objectGetOptions))
<span style="font-size:small <span style="font-size:small
{






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementBaseObject<span style="font-size:small <span style="font-size:small inputArgs = dir.GetMethodParameters(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "CopyEx"<span style="font-size:small <span style="font-size:small );
<span style="font-size:small <span style="font-size:small






<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small foreach<span style="font-size:small <span style="font-size:small (<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small var<span style="font-size:small <span style="font-size:small prop
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small in<span style="font-size:small <span style="font-size:small inputArgs.Properties)
<span style="font-size:small <span style="font-size:small
{






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Console<span style="font-size:small <span style="font-size:small .WriteLine(prop.Name);
<span style="font-size:small <span style="font-size:small
}






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Console<span style="font-size:small <span style="font-size:small .WriteLine(DestinationPath.Replace(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "\"<span style="font-size:small <span style="font-size:small ,
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "\\"<span style="font-size:small <span style="font-size:small ));
<span style="font-size:small <span style="font-size:small
inputArgs[




<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "FileName"<span style="font-size:small <span style="font-size:small ] = DestinationPath.Replace(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "\"<span style="font-size:small <span style="font-size:small ,
<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "\\"<span style="font-size:small <span style="font-size:small );
<span style="font-size:small <span style="font-size:small
inputArgs[




<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "Recursive"<span style="font-size:small <span style="font-size:small ] = Recursive;
<span style="font-size:small <span style="font-size:small
inputArgs[




<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "StartFileName"<span style="font-size:small <span style="font-size:small ] =
<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small null<span style="font-size:small <span style="font-size:small ;
<span style="font-size:small <span style="font-size:small






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small ManagementBaseObject<span style="font-size:small <span style="font-size:small outParams = dir.InvokeMethod(<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "CopyEx"<span style="font-size:small <span style="font-size:small ,
inputArgs, <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small null<span style="font-size:small <span style="font-size:small );
<span style="font-size:small <span style="font-size:small






<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small return<span style="font-size:small <span style="font-size:small ((<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small uint<span style="font-size:small <span style="font-size:small )(outParams.Properties[<span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small <span style="color:#a31515; font-size:small "ReturnValue"<span style="font-size:small <span style="font-size:small ].Value));
<span style="font-size:small <span style="font-size:small
}
}





<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small catch<span style="font-size:small <span style="font-size:small (<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Exception<span style="font-size:small <span style="font-size:small ex)
<span style="font-size:small <span style="font-size:small
{






<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Console<span style="font-size:small <span style="font-size:small .WriteLine(ex.Message +
<span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small <span style="color:#2b91af; font-size:small Environment<span style="font-size:small <span style="font-size:small .NewLine + ex.StackTrace);
<span style="font-size:small <span style="font-size:small

<span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small <span style="color:#0000ff; font-size:small throw<span style="font-size:small <span style="font-size:small ex;

<span style="font-size:small <span style="font-size:small
}
}


When I run the code I get below error:
Invalid method Parameter(s)<br/>
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)<br/>
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
Any I deas as to what am I doing wrong?

View the full article
 
Back
Top