CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2009
    Posts
    34

    Make Windows Service Unable to Terminate?

    Hey,

    I'm working on a Windows Service application and i want this service to be 'unable to terminate' process, so when i go to the Windows Task Manager and i click on terminate on the process, its sais unable to terminate.

    Thanks,
    Dan

  2. #2
    Join Date
    Jul 2007
    Location
    Illinois
    Posts
    517

    Re: Make Windows Service Unable to Terminate?

    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

  3. #3
    Join Date
    Jul 2009
    Posts
    34

    Re: Make Windows Service Unable to Terminate?

    This is what i need, but i dont understand where to use it and how?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Make Windows Service Unable to Terminate?

    Try this.

    Code:
    public partial class MyService : ServiceBase
    {
            public MyService ()
            {
                InitializeComponent();
                CanStop = false;
                CanShutdown = false;
            }
    }
    If it doesn't work, you'll have to load the service under a different account ( maybe 'LocalSystem'? ).

  5. #5
    Join Date
    Jul 2009
    Posts
    34

    Re: Make Windows Service Unable to Terminate?

    Ok, it acctually work but it doesn't exectly what i ment.
    Now i cant stop the service from the Services window in Windows, but i can still do CTRL+ALT+DELETE go to Process and kill it ...

    any ideas?

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Make Windows Service Unable to Terminate?

    Quote Originally Posted by danpe View Post
    Ok, it acctually work but it doesn't exectly what i ment.
    Now i cant stop the service from the Services window in Windows, but i can still do CTRL+ALT+DELETE go to Process and kill it ...

    any ideas?
    See my previous comment:

    If it doesn't work, you'll have to load the service under a different account ( maybe 'LocalSystem'? ).
    To determine which account, identify a service that you know you can't kill with task manager, open it up in the services control applet and see which startup account is used for that service (and use the same for that service).

  7. #7
    Join Date
    Jul 2009
    Posts
    34

    Re: Make Windows Service Unable to Terminate?

    My service is on the SYSTEM, and the process i cant close is on the 'owner' thats the user im logged with...

    When im trying to close the process i cant close its sais "Unable to Terminate Process The operation could not be completed. Access is denied"
    Last edited by danpe; September 30th, 2010 at 02:29 PM.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Make Windows Service Unable to Terminate?

    Quote Originally Posted by danpe View Post
    My service is on the SYSTEM, and the process i cant close is on the 'owner' thats the user im logged with...

    When im trying to close the process i cant close its sais "Unable to Terminate Process The operation could not be completed. Access is denied"
    One way around this is to create a specific machine account and give it the appropriate permissions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured