I'd like to execute a batch file on a remote Windows server to erase log files on a computer that isn't in the same domain as me and for which I have login credentials.
I used the approach below, which worked but yielded no results.
try
{
scope.Connect();
ManagementPath mp = new ManagementPath(servername + "root\\cimv2:Win32_Process");
ManagementClass mo = new ManagementClass(scope, mp, new ObjectGetOptions(null, new TimeSpan(0, 0, 0, 5), true));
ManagementBaseObject inParams = mo.GetMethodParameters("Create");
InvokeMethodOptions options = new InvokeMethodOptions();
inParams.SetPropertyValue("CommandLine", mCommand);
inParams.SetPropertyValue("CurrentDirectory", workingDir);
ManagementBaseObject mbo = mo.InvokeMethod("Create", inParams, options);
Object rv = mbo.GetPropertyValue("returnvalue");
Object prid = mbo.GetPropertyValue("processid");
_OutMessage = "success";
_OutResult = true;
_HttpStatusCode = HttpStatusCode.OK;
}
catch (Exception e)
{
_OutMessage = e.Message.ToString();
_OutResult = false;
_HttpStatusCode = HttpStatusCode.InternalServerError;
}