Announcement Announcement Module
Collapse

myhosting.com Forum Guidelines

Welcome to the myhosting.com Forums! The purpose of this forum is to allow you to discuss topics relating to hosting and topics of interest with other myhosting.com Customers. The primary focus should relate to issues not generally included in our Wiki or Control Panel, or information not provided by our Customer Support Team. Some examples include programming and coding support, web site design ideas and SEO practices.

The forum is not meant as a replacement to our Wiki or Customer Support. We highly recommend searching our Wiki before posting on the forum. Also, if you have a question for our Customer Support team, please contact them as you would normally.

We ask that if you have any complaints or questions relating specifically to your account, that you address them to our Customer Support department. Do not post personal account information such as passwords or other sensitive and private information the forum, as this type of information is best kept secret. Also, please be respectful of other users and refrain from defamatory comments or use of coarse language.

We will visit the forum from time to time, and contribute to various topics. We reserve the right to delete any posts which are deemed offensive or against the spirit of the forum. Any spamming or illegal activity will not be tolerated. We also reserve the right to block any user who violates these guidelines.

To get started, we welcome you to sign up at our User Management site. Any account created there will have access to these forums, our Wiki, our Ideas site and commenting permission on our Status Blog.
See more
See less
[RESOLVED] Toggling a service under Windows7 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [RESOLVED] Toggling a service under Windows7

    I have these set of functions that have been working under WindowsXP and Vista. They Toggle a particular service. That is, they stop the service if it is running, and once it is stopped, it restarts the service. If anything goes wrong, such as a function to OpenSCManager or OpenService, etc... then the error is logged. It has been working for years, but under Win7, something odd is happening.

    1. There are no failures, the return codes from all calls are reported as non-zero (success).
    2. When you do a fresh reboot of Windows7, the "SERVICE_CONTROL_STOP" to the "Dnscache" returns non-zero (success).
    3. All the functions that check the actual status of the service return non-zero.
    4. "(SERVICE_STOPPED == ServiceStatus.dwCurrentState)" will always evaluate to false.

    My toggle service will run and check once a second forever waiting for the service to stop, which it never will. You can go to the Service Manager and verify it is still running.

    Now here is where it gets stranger. You can then go to the service manager and STOP the service (which gets my program out of the wait loop). After this point, until you reboot Windows7, my application will work correctly. It can toggle the service all day and succeed.

    The same code that gets "stuck" on a fresh reboot, will not get stuck after you use the Service Manager (via the control panel or task manager) to stop the service once.

    I did not post my code because it is very basic and you can pretty much look at the MSDN sample code and it looks very much like my code (cause I cut and paste most of it). If you want my code I can post it, although it is very vanilla.

    Is there something special going on with Windows7? Something extra that may need to be done that is not needed on Vista? I have no idea why using the Service Manager "un-breaks" my program.

    BTW my program is another service which runs as LocalSystem, so it has the privileges to do all this. Furthermore all the functions succeed, none of them are returning an error.

    I just have no idea why this is happening on Windows7.
Working...
X