I am an administrator and want to delegate helpdesk stuff to do some applications silent installs which requires admin. rights, I tried below code and always gets error message 'RPC server is unavailable', I cannot figure out what's wrong with my code, any help will be highly appreciated.
public static string ahmed(string machine, string username, string password, string domain)
{
try
{
ConnectionOptions connectionOptions = new ConnectionOptions();
connectionOptions.Authority = "ntlmdomain:" + 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 processClass = new ManagementClass(scope, p, null);
// Create an array containing all
// arguments for the method
object[] methodArgs =
{@"mkdir c:\testtest", null, null, 0};
//Execute the method
object result =
processClass.InvokeMethod(
"Create", methodArgs);
return "done";
}
catch (ManagementException me)
{
return me.Message;
}
catch (COMException ioe)
{
return ioe.Message;
}
}