Start a process with WMI on a remote computer from a share on another remote machine

I have the following code to start a process on a remote computer from a share on a second remote computer, as described in the image:

Connection
(source: microsoft.com )

public class Runner { public static string RunExecutable(string machine, string executable, string username, string password, string domain) { try { ConnectionOptions connectionOptions = new ConnectionOptions(); connectionOptions.Authority = "kerberos:" + domain + @"\" + machine; connectionOptions.Username = username; connectionOptions.Password = password; connectionOptions.Impersonation = ImpersonationLevel.Delegate; connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy; //define the WMI root name space ManagementScope scope = new ManagementScope(@"\\" + machine + "." + domain + @"\root\CIMV2", connectionOptions); //define path for the WMI class ManagementPath p = new ManagementPath("Win32_Process"); //define new instance ManagementClass classInstance = new ManagementClass(scope, p, null); ManagementClass startupSettings = new ManagementClass("Win32_ProcessStartup"); startupSettings.Scope = scope; startupSettings["CreateFlags"] = 16777216; // Obtain in-parameters for the method ManagementBaseObject inParams = classInstance.GetMethodParameters("Create"); // Add the input parameters. inParams["CommandLine"] = executable; inParams["ProcessStartupInformation"] = startupSettings; // Execute the method and obtain the return values. ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null); // List outParams string retVal = outParams["ReturnValue"].ToString(); return "ReturnValue: " + retVal; } catch (ManagementException me) { return me.Message; } catch (COMException ioe) { return ioe.Message; } } } 

There are 5 computers in my environment, all in one domain. 3 are running Windows Server 2008R2, one is Windows 7 and one is Windows XP:

  • Winxp
  • Win7
  • Master2008
  • Slave2008-1
  • Slave2008-2

I run the code from Master2008, the domain controller, and try to start the process on other computers, but I encounter some problems when starting the process on computers with XP and 7.

When I start the process on WinXP and Win7 machines, I get a return value of 8, which is equal to "Unknown error", but when the process starts on Server 2008R2 machines, this works without problems.

All machines were marked as trusted for delegation to AD.

The process I'm trying to start is \\ "machine" \ c $ \ Windows \ System32 \ Calc.exe

I tried to start the process from different machines, and the result was the following (the program runs on Master2008):

 On WinXP - From Win7: Failed (8) - From Slave2008-1: Failed (8) - From Slave2008-2: Failed (8) - From Master2008: Failed (8) On Win7 - From WinXP: Success (0) - From Slave2008-1: Failed (8) - From Slave2008-2: Failed (8) - From Master2008: Failed (8) On Slave2008-1 - From WinXP: Success (0) - From Win7: Success (0) - From Slave2008-2: Success (0) - From Master2008: Success (0) On Slave2008-2 - From WinXP: Success (0) - From Win7: Success (0) - From Slave2008-1: Success (0) - From Master2008: Success (0) 

For some reason, they all do not work on the WinXP machine, but the Win7 machine can be installed from the WinXP machine.

Does anyone have any idea what could be wrong?

+4
source share
2 answers

There seems to be no problem with the code. I tried to make a simple application to run instead of "calc.exe", and it worked as it should.

The problem was that I tried to run "calc.exe" from 64-bit servers on 32-bit clients. In addition, "calc.exe" in Windows7 will not work on WindowsXP.

+1
source

Does not work. http://technet.microsoft.com/en-us/library/ee156574.aspx

You cannot use the delegate impersonation level if all user and computer accounts involved in the transaction were not marked as "Trusted" for delegation in Active Directory. This helps minimize security risks. Although the remote computer can use your credentials, it can only do this if it and other computers involved in the transaction are trusted with delegation.

0
source

Source: https://habr.com/ru/post/1393351/


All Articles