Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:22:09+00:00 2026-06-12T22:22:09+00:00

We have a service in our project that runs and we need it to

  • 0

We have a service in our project that runs and we need it to get a command on log off. We could send a command via our console, but the console is a separate program which could not be running. It does not necessarily need to stop, but it does need to get a command of some sort. Is there anything with in the service which can catch a Log Off event?

[10/17/12 10:45] – The service is running as Local System.

[10/17/12 12:07] – I added the following method, but I am not getting any output when I log off or onto the computer even though I am successfully writing to the log with this message I will try again rebuilding my solution, but wanted to post this here in case I am doing something wrong.

protected override void OnSessionChange(SessionChangeDescription changeDescription)
{
        WriteToDebugLog(new string[] { "OnSessionChange()",
                                        DateTime.Now.ToLongTimeString() + " - Session change notice received: " + changeDescription.Reason.ToString() + "  Session ID: " + changeDescription.SessionId.ToString(),
                                       "Information" });
        base.OnSessionChange(changeDescription);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:22:10+00:00Added an answer on June 12, 2026 at 10:22 pm

    Unfortunately Services cannot run per-user, they’re system wide. You may modify your service to detect when the user log-off but then it won’t be started again when the user log-in again. As alternative you may use a second service to monitor log-in activity (using OnSessionChanged as pointed out by @rene) and to start/stop the first service according.

    It’s a little bit tricky and you have to install a second service, I prefer a more simple solution using scripting.

    PowerShell

    You can use two PowerShell scripts, this is to start the service:

    Start-Service -name "YourServiceName"
    

    This is to stop the service:

    Stop-Service -name "YourServiceName"
    

    To configure this scripts to be executed take a look here. In short you have to change policy configuration in HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System!RunUserPSScriptsFirst to run your scripts when needed.

    “Old” shell

    You’re not forced to use PowerShell, to start/stop a service can be done using shell commands:

    sc start YourServiceName
    

    and

    sc stop YourServiceName
    

    See this post for how to execute a batch file (or a command) at log-off. In short you have to add an entry to HKCU\Software\Policies\Microsoft\Windows\System\Scripts\Logoff for log-off and HKCU\Software\Policies\Microsoft\Windows\System\Scripts\Logon for log-on (but there are many many different places where you can put your scripts for log-on).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a service hosted behind our firewall that receives request forwarded through to
I have a Windows Service written in C# that handles all of our external
Hi I have an web service based app that will interchange data with our
We have a Java web service that we call from our application. When we
we have a public asmx service that is accessed by our clients through SOAP
The situation: We have a library project that houses much of our code for
I need to implement a project that will consume XML Web Service from other
In our project we have Service and DAO layers in separate Maven modules. Service
I have created a WCF service in our Project. There are many methods inside
Here I create one project that will track our current location. But I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.