April 21st, 2010 05:25 AM
#1
WMI remote execution local admin
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;
try
{
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);
manScope.Connect();
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?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks