vendredi 14 août 2015

Execute remotely a command and get result

i am a newbie at c# somebody could help me for a program that runs on remote pc and get the result.

ManagementScope wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", "pc"));
        wmiScope.Connect();


        var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());

        ManagementBaseObject inParams = wmiProcess.GetMethodParameters("Create");
        //inParams["CommandLine"] = "notepadd.exe" + " \"" + "dir"+ "\"";
        inParams["CommandLine"] = "cmd.exe " + " \"" + " ipconfig /all " + "\"";
        inParams["CurrentDirectory"] = @"c:\windows\system32";

        ManagementBaseObject result = wmiProcess.InvokeMethod("Create", inParams,null);

        Debug.WriteLine(result["returnValue"]);
        Debug.WriteLine(result["processId"]);

        return Json(result, JsonRequestBehavior.AllowGet);

I'm getting a JSON dictionary but there are nothing that i want.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire