Click here to Skip to main content
15,791,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey all,
I have a winServer 2008 machine. I have created a new local user.
In order to make him an admin all I have to do is to add it to the "administrators" group. right?
now, I wrote a c# code that supposed to connect that local user and execute some exe file remotely.

        static void Main(string[] args)
            string remoteMachine = "HV-BENDA";              
            string sBatFile = string.Empty;
                 string _cmd = "D:\\LocalUserManagerDLL3.5\\RunDll\\bin\\Debug\\RunDll.exe";
                if (_cmd.Trim() == string.Empty)
                    Console.WriteLine("No command entered using default command for test :" + _cmd);
                ConnectionOptions connOptions = new ConnectionOptions();
                connOptions.Username = "HV-BENDA\test3";
                connOptions.Password = "1234";
                connOptions.Impersonation = ImpersonationLevel.Impersonate;
                connOptions.EnablePrivileges = true;
                ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", remoteMachine), connOptions);
                ObjectGetOptions objectGetOptions = new ObjectGetOptions();
                ManagementPath managementPath = new ManagementPath("Win32_Process");
                ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
                ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
                inParams["CommandLine"] = sBatFile;
                ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
                Console.WriteLine("Creation of the process returned: " + outParams["returnValue"]);
                Console.WriteLine("Process ID: " + outParams["processId"]);
            catch (Exception ex)
                Console.WriteLine("Error " + ex.Message);

but the following exception is thrown from the manScope.Connect(); line
"The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)"

when I omit
connOptions.Username = "HV-BENDA\test3";
connOptions.Password = "1234";
everything works just fine.This, as I understand, connects with my current user (which is domain admin and not just local admin). So I have tried to use these two lines with my current user credentials- but the same exception was thrown.

does anyone know how to resolve it?

1 solution

Your code is connecting to the remote machine using the supplied credentials, NOT running the remote .EXE using them. The RPC is unavailable because the user specified doesn't have permissions to create objects on the remote machine.

WMI has no facility built in to create processes as other users.

You can either use the third party tool called PSEXEC or launch an exquivlent RunAs command line on the remote machine using some of the WMI code you have now.
Share this answer

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