Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to start a process on a remote Machine using WMI but the Create method can't be used for remote connections? P.S : I don't want to use PsTools

Here's a sample of the code :


ConnectionOptions connectoptions = new ConnectionOptions();

connectoptions.Username = "";
connectoptions.Password = "";


//IP Address of the remote machine
string ipAddress = "";
ManagementScope scope = new ManagementScope(@"\\" + ipAddress + @"\root\cimv2");
scope.Options = connectoptions;
//Define the WMI query to be executed on the remote machine
SelectQuery query = new SelectQuery("select * from Win32_Process");

C#
using (ManagementObjectSearcher searcher = new
                        ManagementObjectSearcher(scope, query))
            {

                ManagementObjectCollection collection = searcher.Get();

                foreach (ManagementObject process in collection)
                {

               object[] theProcessToRun = { "notepad.exe" };

                    process.InvokeMethod("Create", theProcessToRun ); //cannot be used remotely :(
                }

            }
Posted
Updated 8-Oct-14 23:12pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900