Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,104 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,698 people online right now. Registration is fast and FREE... Join Now!




Error when using ServiceController

2 Pages V  1 2 >  
Reply to this topicStart new topic

Error when using ServiceController

matthewhaigh
13 Nov, 2007 - 01:50 PM
Post #1

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 19


My Contributions
error says im missing directive or assembly method

CODE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Service
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BtnStop_Click(object sender, EventArgs e)
        {

                ServiceController sc = new ServiceController("service");

                sc.Stop();

        }
    }
}


This post has been edited by matthewhaigh: 13 Nov, 2007 - 01:51 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Error When Using ServiceController
13 Nov, 2007 - 01:59 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,920



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Can you post the exact error message?

More than likely, you need to add the directive to use the ServiceController class

CODE

using System.ServiceProcess;

User is online!Profile CardPM
+Quote Post

matthewhaigh
RE: Error When Using ServiceController
13 Nov, 2007 - 03:08 PM
Post #3

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 19


My Contributions
QUOTE(jayman9 @ 13 Nov, 2007 - 02:59 PM) *

Can you post the exact error message?

More than likely, you need to add the directive to use the ServiceController class

CODE

using System.ServiceProcess;



attached image of error
thanks

Attached Image
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Error When Using ServiceController
13 Nov, 2007 - 06:15 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,920



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You are going to need to add a reference to System.ServiceProcess to your project.

Goto the project menu and select Add Reference...scroll down the list on the .NET tab until you find System.ServiceProcess and put a check in the box. Then click the OK button.

Now add the directive I gave you in my first post to your project and your good to go.
User is online!Profile CardPM
+Quote Post

matthewhaigh
RE: Error When Using ServiceController
14 Nov, 2007 - 08:30 AM
Post #5

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 19


My Contributions
QUOTE(jayman9 @ 13 Nov, 2007 - 07:15 PM) *

You are going to need to add a reference to System.ServiceProcess to your project.

Goto the project menu and select Add Reference...scroll down the list on the .NET tab until you find System.ServiceProcess and put a check in the box. Then click the OK button.

Now add the directive I gave you in my first post to your project and your good to go.

i added the directive and that solved that probelm, so i tried using it to stop the clock (W32Time) and it crashed with the error below in the picture file..... any ideas?Attached Image
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Error When Using ServiceController
14 Nov, 2007 - 09:57 AM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,920



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Why are you trying to stop this service?

It appears that W32Time service only runs on Windows 2000, at least from what I have been able to find.

If you click the "View Detail.." link at the bottom of the error message you will find that the Inner Exception states that the service is not running. That is why you are getting an InvalidOperationException.

You cannot stop a service that isn't running.
User is online!Profile CardPM
+Quote Post

PsychoCoder
RE: Error When Using ServiceController
14 Nov, 2007 - 10:09 AM
Post #7

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8600
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Actually w32time runs on XP as well, and most versions of Windows I do believe. I had a time synchronizing issue on my computer (running XP) and had to stop and start w32time to fiz it.
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Error When Using ServiceController
14 Nov, 2007 - 01:51 PM
Post #8

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,920



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Ah, I see..couldn't find much searching for w32time, but when I searched for "Windows Time Synchronization service" then bingo.

This service is only running on 2 of 3 computers at my house. Just so happens I was working on the computer that doesn't have the service running. Go figure.

Anyway back to the problem at hand, matthewhaigh, I would suggest checking to see if the service is actually running on your computer. It may not be running and this could be why you are getting the error message. To check if it is already running, right click on the My Computer icon on your desktop and select "Manage" from the menu. Open "Services and Applications" by clicking the little plus sign next to it. Select Services and on the right side of your screen you will see all the services on your computer. Scroll the list and look for "Windows Time", select it, then look up in the left corner (red box) and see if the service needs to be started. See screenshot below, as you can see it is not currently running on my computer. Although I started it after I posted this.


Attached thumbnail(s)
Attached Image
User is online!Profile CardPM
+Quote Post

matthewhaigh
RE: Error When Using ServiceController
14 Nov, 2007 - 02:09 PM
Post #9

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 19


My Contributions
QUOTE(jayman9 @ 14 Nov, 2007 - 02:51 PM) *

Ah, I see..couldn't find much searching for w32time, but when I searched for "Windows Time Synchronization service" then bingo.

This service is only running on 2 of 3 computers at my house. Just so happens I was working on the computer that doesn't have the service running. Go figure.

Anyway back to the problem at hand, matthewhaigh, I would suggest checking to see if the service is actually running on your computer. It may not be running and this could be why you are getting the error message. To check if it is already running, right click on the My Computer icon on your desktop and select "Manage" from the menu. Open "Services and Applications" by clicking the little plus sign next to it. Select Services and on the right side of your screen you will see all the services on your computer. Scroll the list and look for "Windows Time", select it, then look up in the left corner (red box) and see if the service needs to be started. See screenshot below, as you can see it is not currently running on my computer. Although I started it after I posted this.


yea i checked and its running... basically i was just using it as an example servcie to stop, i want to make a service stopper to block the netsupport software at college. Basically it runs around a service called client32.exe from what i can gather and because i can't access the task manager i was trying to create an alternative to stop servcies with

mat
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Error When Using ServiceController
14 Nov, 2007 - 03:43 PM
Post #10

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,920



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Then can you post the Inner Exception message that you are receiving on the error message when it is thrown. That may provide a better indication of the problem. Click "View Detail..", click the little plus symbol next to the exception and post the Inner Exception message.

Now that the service is running on my computer, I am having no problem starting and stopping it through code.
User is online!Profile CardPM
+Quote Post

PsychoCoder
RE: Error When Using ServiceController
14 Nov, 2007 - 03:57 PM
Post #11

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8600
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
QUOTE(matthewhaigh @ 14 Nov, 2007 - 02:09 PM) *

yea i checked and its running... basically i was just using it as an example servcie to stop, i want to make a service stopper to block the netsupport software at college. Basically it runs around a service called client32.exe from what i can gather and because i can't access the task manager i was trying to create an alternative to stop servcies with
mat


So in all actuality you're asking us for help in writing an application that will circumvent security they have setup for the workstations at your school? Now that this is in the open do you really think we're going to help you further in your endeavor?

As far as I'm concerned what you're trying to do falls under this category, unless you can prove me wrong smile.gif

User is offlineProfile CardPM
+Quote Post

matthewhaigh
RE: Error When Using ServiceController
14 Nov, 2007 - 04:07 PM
Post #12

New D.I.C Head
*

Joined: 20 Sep, 2007
Posts: 19


My Contributions
QUOTE(PsychoCoder @ 14 Nov, 2007 - 04:57 PM) *

QUOTE(matthewhaigh @ 14 Nov, 2007 - 02:09 PM) *

yea i checked and its running... basically i was just using it as an example servcie to stop, i want to make a service stopper to block the netsupport software at college. Basically it runs around a service called client32.exe from what i can gather and because i can't access the task manager i was trying to create an alternative to stop servcies with
mat


So in all actuality you're asking us for help in writing an application that will circumvent security they have setup for the workstations at your school? Now that this is in the open do you really think we're going to help you further in your endeavor?

As far as I'm concerned what you're trying to do falls under this category, unless you can prove me wrong smile.gif


tbh its just a challange lol a little fun thats how they see it, the I.T tutors 'n' all

QUOTE(jayman9 @ 14 Nov, 2007 - 04:43 PM) *

Then can you post the Inner Exception message that you are receiving on the error message when it is thrown. That may provide a better indication of the problem. Click "View Detail..", click the little plus symbol next to the exception and post the Inner Exception message.

Now that the service is running on my computer, I am having no problem starting and stopping it through code.


i have included the info u requested

cheers

mat

Attached ImageAttached Image
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 09:04PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month