Click here to Skip to main content
15,917,454 members
Home / Discussions / C#
   

C#

 
AnswerRe: Simple Example of using Enum Type why we use them? Pin
PIEBALDconsult5-Dec-09 18:32
mvePIEBALDconsult5-Dec-09 18:32 
Questioninserting words into tablelayout Pin
someone295-Dec-09 15:53
someone295-Dec-09 15:53 
AnswerRe: inserting words into tablelayout Pin
Luc Pattyn5-Dec-09 16:21
sitebuilderLuc Pattyn5-Dec-09 16:21 
QuestionWhy does ReSharper implement Equals like this? Pin
CaptainSeeSharp5-Dec-09 15:16
CaptainSeeSharp5-Dec-09 15:16 
AnswerRe: Why does ReSharper implement Equals like this? Pin
N a v a n e e t h5-Dec-09 16:52
N a v a n e e t h5-Dec-09 16:52 
QuestionAdd a dynamic number of labels to form or panel Pin
bolikej5-Dec-09 12:54
bolikej5-Dec-09 12:54 
AnswerRe: Add a dynamic number of labels to form or panel Pin
Luc Pattyn5-Dec-09 13:00
sitebuilderLuc Pattyn5-Dec-09 13:00 
QuestionStopping remote services with WMI 'RPC not available' Pin
Jacob Dixon5-Dec-09 9:05
Jacob Dixon5-Dec-09 9:05 
I am having a hard time figuring this out. My applications is using WMI to get information about a remote computers disk drives, installed applications, and services (all of this works fine). I can seem to get all this information but I cannot get the computer to stop a remote service.

I keep getting "RPC server is unavailable". How is this possible? I am able to retrieve information from these computers so it can't be unavailable.

At first I kept getting 'Access Denied' errors. I was trying to make it use the windows username and passwords somehow instead of having to enter a username and password.

So now I'm doing this:

ConnectionOptions conn = new ConnectionOptions();
conn.Impersonation = ImpersonationLevel.Impersonate;
conn.Username = "DOMAIN\username";
conn.Password = "password";
conn.EnablePrivileges = true;


Like I said.. I can connect and get all the information in the world I want, but cannot seem to stop a service. I read this other article about settings permissions and I have already tried that by going through computer management on the server.

Oh and by the way I am using the top domain admin user to do this.. so there is not another user in this domain that has more rights.


If you are interested in the whole code it is here: (Thanks to (Windows Management Instrumentation (WMI) Implementation[^]) for most of it)


    ServiceInfo service = (ServiceInfo)serviceInfo;

    ManagementOperationObserver observer = new ManagementOperationObserver();
    MyHandler completionHandlerObj = new MyHandler();
    observer.ObjectReady += new ObjectReadyEventHandler(completionHandlerObj.Done);

    try
    {
        ConnectionOptions conn = new ConnectionOptions();
        conn.Impersonation = ImpersonationLevel.Impersonate;
        conn.Username = "DOMAIN\username";
        conn.Password = "password";
        conn.EnablePrivileges = true;

        ManagementScope scope = new ManagementScope("\\\\" + service.DNSHost + "\\root\\CIMV2", conn);
        scope.Connect();

        ManagementObjectSearcher mos = new ManagementObjectSearcher(scope, new ObjectQuery("SELECT * FROM Win32_Service WHERE DisplayName='" + service.item.Text + "'"));
        foreach (ManagementObject mo in mos.Get())
        {
            bool Started = Convert.ToBoolean(service.item.SubItems[1].Text);
            if (Started)
                mo.InvokeMethod(observer, "StopService", null);
            else if (!Started)
                mo.InvokeMethod(observer, "StartService", null);

            int intCount = 0;
            while
            (!completionHandlerObj.IsComplete)
            {
                if (intCount > 10)
                {
                    MessageBox.Show("Terminate process timed out.", "Terminate Process Status");
                    break;
                }
                System.Threading.Thread.Sleep(500);
                intCount++;
            }

            //see if call was successful.
            if (completionHandlerObj.ReturnObject.Properties["returnValue"].Value.ToString() == "0")
            {
                if (!Started)
                {
                    service.item.SubItems[1].Text = "True";
                    service.item.SubItems[1].BackColor = Color.LimeGreen;
                    service.item.SubItems[1].ForeColor = Color.Black;
                }
                else
                {
                    service.item.SubItems[1].Text = "False";
                    service.item.SubItems[1].BackColor = Color.Red;
                    service.item.SubItems[1].ForeColor = Color.White;
                }
            }
            else
            {
                MessageBox.Show("Failed.", "Start/Stop Service Failure");
            }

        }
    }
    catch (Exception ex) { MessageBox.Show("Error starting/stoppping service.\n\n" + ex.Message); }
    finally
    {
        Invoke((Action)(() => { picProgressServices.Visible = false; }));
    }
}


AnswerRe: Stopping remote services with WMI 'RPC not available' Pin
Jacob Dixon5-Dec-09 9:15
Jacob Dixon5-Dec-09 9:15 
Questionmove the object Pin
machisiou5-Dec-09 5:48
machisiou5-Dec-09 5:48 
AnswerRe: move the object Pin
Luc Pattyn5-Dec-09 6:01
sitebuilderLuc Pattyn5-Dec-09 6:01 
QuestionClass Diagram Code Generation Pin
Randal Vance Cunanan5-Dec-09 5:39
Randal Vance Cunanan5-Dec-09 5:39 
AnswerRe: Class Diagram Code Generation Pin
Tony Richards5-Dec-09 5:59
Tony Richards5-Dec-09 5:59 
GeneralRe: Class Diagram Code Generation Pin
Randal Vance Cunanan5-Dec-09 6:03
Randal Vance Cunanan5-Dec-09 6:03 
GeneralRe: Class Diagram Code Generation Pin
0x3c05-Dec-09 6:38
0x3c05-Dec-09 6:38 
GeneralRe: Class Diagram Code Generation Pin
Randal Vance Cunanan5-Dec-09 11:58
Randal Vance Cunanan5-Dec-09 11:58 
GeneralRe: Class Diagram Code Generation Pin
Rozis5-Dec-09 13:18
Rozis5-Dec-09 13:18 
GeneralRe: Class Diagram Code Generation Pin
Randal Vance Cunanan5-Dec-09 16:21
Randal Vance Cunanan5-Dec-09 16:21 
GeneralRe: Class Diagram Code Generation Pin
0x3c05-Dec-09 19:55
0x3c05-Dec-09 19:55 
GeneralRe: Class Diagram Code Generation Pin
Randal Vance Cunanan5-Dec-09 19:57
Randal Vance Cunanan5-Dec-09 19:57 
GeneralRe: Class Diagram Code Generation Pin
harold aptroot5-Dec-09 6:56
harold aptroot5-Dec-09 6:56 
QuestionCustom text with Special Field inside Crystal Reports. Pin
Saksida Bojan5-Dec-09 4:53
Saksida Bojan5-Dec-09 4:53 
AnswerRe: Custom text with Special Field inside Crystal Reports. Pin
Natza Mitzi6-Dec-09 10:09
Natza Mitzi6-Dec-09 10:09 
GeneralRe: Custom text with Special Field inside Crystal Reports. Pin
Saksida Bojan6-Dec-09 19:27
Saksida Bojan6-Dec-09 19:27 
QuestionSending a TCP & UDP packet... Pin
3bood.ghzawi5-Dec-09 2:42
3bood.ghzawi5-Dec-09 2:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.