Execute commands on the remote machine via WMI (wmi:windows management
interface
It is possible to access the constituent units of different operating systems (Windows systems) through a common interface, which can be used to efficiently manage remote and local computers.
Public Static voidExecuteremote (stringServerhostname,stringDomainstringUserName,stringPasswordstringStrcommand,stringpath) { //connectionoptions Specifies the settings required to generate a WMI connectionConnectionOptions connoption =Newconnectionoptions (); Connoption.username= domain +@"\"+UserName; Connoption.password=password; //Managementpath wraps the path to generate and analyze WMI objectsManagementpath Mngpath=NewManagementpath (@"\\"+ Serverhostname +@"\root\cimv2:win32_process"); Managementscope Scope=NewManagementscope (Mngpath, connoption); Scope. Connect (); //The objectgetoptions class is the option to specify to get management ObjectsObjectgetoptions objoption =Newobjectgetoptions (); //ManagementClass is a public Information model (CIM) management class that, through members of the class, can access WMI data using a specific WMI ClasspathManagementClass classinstance =NewManagementClass (Scope, Mngpath, objoption); Managementbaseobject Inparams= Classinstance.getmethodparameters ("Create"); //setting command line argumentsinparams["CommandLine"] =@"cmd.exe/c"+ @path +@"-infile"+@strCommand; Managementbaseobject Outparams= Classinstance.invokemethod ("Create", Inparams,NULL);}
RPC cannot access the problem resolution:
Enable firewalls to allow remote logons to netsh firewall set service remoteadmin
WMI Execution Remote file (RPC)